Question

I am creating an Excel sheet from an XML where I need to produce a result like:

Current node name | Parent name

I have previously worked with traversing through an XML file and retrieving entries from it.. But I don't know how to find the parent of a particular node.

Does anybody have any knowledge how to find the parent node of a current node?

Sample XML:

<node>
  <id> 1 </id>
  <name> One </name>
  <node>
    <id> 2 </id>
    <name> Two </name>
  </node>
  <node> 
    <id> 3 </id>
    <name> Three </name>
  </node>
 .....

Here, nodes with id 2 and 3 have node with id = 1 as their parent.. So I want my Excel to look like:

Child | Parent
2     | 1 
3     | 1

Thanks in advance.

Was it helpful?

Solution

You can use the getParentNode method:

node.getParentNode();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top