BulkChangeResult restore(Reader reader, @Nullable QProfileName toProfileName) {
try {
String profileLang = null, profileName = null;
List<RuleActivation> ruleActivations = Lists.newArrayList();
SMInputFactory inputFactory = initStax();
SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
rootC.advance(); // <profile>
if (!rootC.getLocalName().equals("profile")) {
throw new IllegalArgumentException("Backup XML is not valid. Root element must be <profile>.");
}
SMInputCursor cursor = rootC.childElementCursor();
while (cursor.getNext() != null) {
String nodeName = cursor.getLocalName();
if (StringUtils.equals("name", nodeName)) {
profileName = StringUtils.trim(cursor.collectDescendantText(false));