My xml looks like this-
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Objects>
<object1>object1Value</object1>
<object2>object1Value</object2>
</Objects>
</root>
To show all objects under “Objects” I am using code-
List collected_objects = rootNode.getChildren("Objects");
ListIterator litr = collected_objects.listIterator();
while (litr.hasNext()) {
Element element = (Element) litr.next();
System.out.println(element.toString());
}
but it displays-
[Element: <Objects/>]
Why isn’t it showing two objects?
You have to call a
NodeList objectList = element.getChildNodes()on each of thecollected_objectsand iterate through the returned list, since in your XML<object1>, <object2>...nodes are children of the<Objects>.