case TEXT: {
nodes = readTextF(src, type);
break;
}
case ATTRIBUTE: {
Element elem = addAttributesAndNamespaces ? current : null;
nodes = readAttributeF(src, elem, type);
break;
}
case BEGIN_ELEMENT: {
Element elem = readStartTagF(src, type, false);
stack.push(elem); // even if it's null
if (elem != null) {
current.insertChild(elem, current.getChildCount());
current = elem; // recurse down
}
addAttributesAndNamespaces = elem != null;
continue;
}
case END_ELEMENT: {
Element elem = stack.pop();
if (elem == null) {
continue; // skip element
}
ParentNode parent = elem.getParent();
if (parent == null) throwTamperedWithParent();
if (parent instanceof Document) {
return; // we're done with the root element
}
current = (Element) parent; // recurse up
nodes = factory.finishMakingElement(elem);
if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case)
continue; // optimization: no need to remove and then readd same element
}
if (current.getChildCount()-1 < 0) throwTamperedWithParent();
current.removeChild(current.getChildCount()-1);
break;
}
case COMMENT: {
nodes = readCommentF(src, type);
break;
}
case NAMESPACE_DECLARATION: {
Element elem = addAttributesAndNamespaces ? current : null;
readNamespaceDeclaration(src, elem, type);
continue;
}
case PROCESSING_INSTRUCTION: {
nodes = readProcessingInstructionF(src);