Sloppy parser only inserts a wrapper tag when it needs to

This commit is contained in:
Vhati 2013-08-28 01:23:50 -04:00
parent ae48ec87ab
commit b93c4fffbf

View file

@ -61,7 +61,7 @@ public class SloppyXMLParser {
public Document build( CharSequence s ) throws JDOMParseException {
Document doc = new Document();
Element rootNode = new Element( "wrapper" );
doc.addContent( rootNode );
doc.setRootElement( rootNode );
Parent parentNode = rootNode;
int sLen = s.length();
@ -195,6 +195,17 @@ public class SloppyXMLParser {
}
}
if ( rootNode.getChildren().size() == 1 ) {
// No need for the wrapper, promote its only child to root.
Element newRoot = rootNode.getChildren().get( 0 );
newRoot.detach();
for ( Namespace ns : rootNode.getAdditionalNamespaces() ) {
newRoot.addNamespaceDeclaration( ns );
}
doc.setRootElement( newRoot );
}
return doc;
}