public void endElement(String uri, String localname, String name) {
Stack<Node> children = siblings.pop();
TempNode c = null;
Node n = siblings.peek().pop();
if (n instanceof Element) {
Element e = (Element) n;
AttrNode a = e.getFirstAttr();
while (!children.isEmpty()) {
Node m = children.pop();
if (m instanceof AttributeGap) { // element with agap child
a = ((AttributeGap) m).copy(a);
} else {
c = ((TempNode) m).copy(c);
}
}
n = e.copy(a, c, e.getNextSibling());
} else if (n instanceof AttributeGap) {
if (!siblings.peek().isEmpty()) {
Node m = siblings.peek().pop();
if (m instanceof Element) { // element with agap successor
Element f = (Element) m;
m = f.copy(((AttributeGap) n).copy(f.getFirstAttr()), f.getFirstChild(), f.getNextSibling());
n = null;
}
siblings.peek().push(m);
}
}