XMLRoot
elements are Nodes which don't have a parent and have optionally a declared encodingXMLRoot
element will have this encoding.XMLTreeHandler
trim CDATA content in the XML file, and considers that the CDATA content is null
if the trimmed CDATA content is empty. For example in this case all the nodes have a null
CDATA content except the second
which will have the "my content" CDATA content:<root desc="example"> <element name="first"> <element name="second">my content</element> <element name="third"/> </element> </root>The XMLTreeHandler.preserveSpace(boolean) method allows to preserve the space characters in the CDATA content. For example in this example here:
<root desc="example"> <element name="first">the first line the second line </element> </root>
XMLTreeHandler
will not keep the line numbers for the nodes. The resulting nodes NumberedNode.getLineNumber() method will return -1.<root name="example"> <element name="first"> <element name="second"/> </element> </root>If we create an iterator on the root node:
next()
method will return the root nodenext()
method will return the first
nodenext()
method will return the second
nodehasNext()
methods will return false<root desc="example"> <element name="first"> <element name="second"/> <element name="third"/> </element> </root>And the NodePath:
NodePath path = new NodePath(); path.addNode("root"); path.addNode("element"); Node node = path.addNode("element", 1); node.setAttribute("name", "changed");Then the result of the XMLTreeReplacer.replace(File, File, NodePath...) method with the NodePath will be:
<root desc="example"> <element name="first"> <element name="second"/> <element name="changed"/> </element> </root>
XMLDocumentBuilderFactory factory = XMLDocumentFactory.getInstance(); Document document = factory.parse(root);
Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences