private Element popStackToSuitableContainer(Tag tag) {
while (!stack.isEmpty() && !(stack.getLast() instanceof XmlDeclaration)) {
Node lastNode = stack.getLast();
if (lastNode instanceof Element) {
Element last = (Element) lastNode;
if (canContain(last.tag(), tag))
return last;
else
stack.removeLast();
}
}