}
ParentNode parent = elem.getParent();
if (parent == null) throwTamperedWithParent();
currents[i] = parent; // recurse up
Nodes nodes = receivers[i].finishMakingElement(elem);
if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case)
if (parent instanceof Document) hasRootElement[i] = true;
continue; // optimization: no need to remove and then readd same element
}
if (parent.getChildCount()-1 < 0) throwTamperedWithParent();
if (parent instanceof Element) { // can't remove root element
parent.removeChild(parent.getChildCount()-1);
}
appendNodes(parent, nodes, i);
} catch (RuntimeException e) {
onException(i, e);
}
}
if (unused.getParent() instanceof Document) {
return new Nodes(unused); // XOM documents must have a root element
}
return NONE;
}