xml.space="&reserve&
XML declaration (by default spaces are not preserved)int
option to the methods, such as:AND
of the following values:XMLRoot root = XMLNodeUtilities.getNode(xmlURL, XMLNodeUtilitiesOptions.KEEP_LINE_NUMBERS & XMLNodeUtilitiesOptions.NAMESPACE_AWARE);
XMLNodeUtilities
class has methods which will preserve the spaces when getting the root node from an URL, a File, a Reader, or a String. Some of these methods allow to preserve spaces in CDATA content. For example in this example here:<root desc="example"> <element name="first">the first line the second line </element> </root>If you perform
XMLNodeUtilities.getRootNode(<the XML file>, false, false, true, false)
, the spaces in CDATA content will be preserved.
XMLNodeUtilities
class has methods which will keep the line numbers for the nodes. The resulting nodes NumberedNode.getLineNumber() method will return the associated line number in the XML file.XMLNodeUtilities.getRootNode(<the XML file>, false, false, false, true)
, the line numbers will be preserved.
Files.newBufferedReader(path, charset)
method.
<root desc="example"> <element1 name="first"> <element2 name="second"/> <element1 name="third"/> </element1> </root>If we apply:
XMLRoot root = XMLNodeUtilities.getRootNode(<the XML file>); List<XMLNode> nodes = XMLNodeUtilities.search(root, "element1", false);The
nodes
result will return only one element because the search only look for direct children of the node:XMLRoot root = XMLNodeUtilities.getRootNode(<the XML file>); List<XMLNode> nodes = XMLNodeUtilities.search(root, "element1", true);The
nodes
result will return two elements because the search look recursively for all children:<root desc="example"> <element2 name="first"/> <element1 name="second"/> <element3 name="third"/> </root>If we apply:
XMLRoot root = XMLNodeUtilities.getRootNode(<the XML file>); List<String> list = new ArrayList<>; list.add("element1"); list.add("element3"); List<XMLNode> nodes = XMLNodeUtilities.searchForNames(root, list, false);The
nodes
result will return two elements:<root desc="example"> <element1 name="first"> <element2 name="second"/> <element1 name="third"/> </element1> </root>If we apply:
XMLRoot root = XMLNodeUtilities.getRootNode(<the XML file>); XMLNode node = XMLNodeUtilities.searchFirst(root, "element1", false);The
node
result will return:Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences