Sloppy parser only inserts a wrapper tag when it needs to
This commit is contained in:
parent
ae48ec87ab
commit
b93c4fffbf
1 changed files with 12 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue