Let's say, we have a XML as follows:
<Parent>
<Child1>
<Child2>
<Child3>
<ElementNode1>ABC</ElementNode1>
<ElementNode2>DEF</ElementNode2>
<ElementNode3>GHI</ElementNode3>
</Child3>
</Child2>
</Child1>
</Parent>
Now if we consider, the root node is at level 1, then how to find in a java program, the elements Child1
, Child2
, Child3
, ElementNode2
are at which level?
I have read about the parsers DOM and DOM4J; but could not find a way.
I expect the output as follows:
Level of Child1 is 2
Level of Child2 is 3
Level of Child3 is 4
Level of ElementNode1 is 5
Level of ElementNode2 is 5