Reputation: 617
I have this XML code:
<root>
<node>
</first_child>
</second_child>
</third_child>
</node>
</root>
I need to take all children nodes one by one and save like three Node variable using DOM.
If I use
doc.getElementsByTagName("node");
I take this "node" with all the children, while I need only "first_child, second_child and third_child"
How to obtain this?
Upvotes: 0
Views: 3128
Reputation: 30097
Element el;
el = (Element) doc.getElementsByTagName("node").item(0);
el.getChildNodes();
Upvotes: 1
Reputation: 3727
Element el = (Element)(doc.getElementsByTagName("node").item(0));
NodeList children = el.getChildNodes();
for (int i=0; i<children.getLength(); i++) {
System.out.println(children.item(0).getNodeValue());
}
Upvotes: 2
Reputation: 325
You can get the children in this way.
var children = document.getElementById('node').getElementsByTagName('*');
Upvotes: 0