FilePosition endPos = checkEnd(elementStack);
DocumentFragment root = elementStack.getRootElement();
Node firstChild = root.getFirstChild();
if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) {
throw new ParseException(new Message(
DomParserMessageType.MISSING_DOCUMENT_ELEMENT, endPos));
}
// Check that there isn't any extraneous content after the root element.
for (Node child = firstChild.getNextSibling(); child != null;
child = child.getNextSibling()) {
switch (child.getNodeType()) {
case Node.COMMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
continue;
case Node.TEXT_NODE:
if ("".equals(child.getNodeValue().trim())) { continue; }
break;
default: break;
}
throw new ParseException(new Message(
DomParserMessageType.MISPLACED_CONTENT,
Nodes.getFilePositionFor(child)));
}
Nodes.setFilePositionFor(doc, Nodes.getFilePositionFor(root));