xml.space="&reserve&
XML declaration (by default spaces are not preserved)<root desc="example"> <element name="first">the first line the second line </element> </root>If you perform:
XMLNodeUtilities2 utils = new XMLNodeUtilities2(); utils.preserveSpaces(true); XMLRoot root = XMLNodeUtilities.getRootNode(<the XML file>);The spaces in CDATA content will be preserved.
<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 ercursively 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