Subject:Get the root node name Author:Sushant Prabhu Date:16 Nov 2006 04:28 AM
Hi All
I have the following xml
*************************************
<node cid="1" oid="2">
<node_name>India</node_name>
<node cid="11" oid="4">
<node_name>Maharashtra</node_name>
<node cid="33" oid="8">
<node_name>Dadar</node_name>
</node>
*************************************
In this I want to retrieve the node_name at the root level which is India. But I do not want to retrieve by using relative path like ../node_name or ../../node_name as the number of sub nodes under some xml instance root node is not standard. In some cases the nodes could be 1 or 3 or 5.
What I want to do by processing (something like using ancestor ) get the topmost parent & then fetch the value for the same. I cannot use the parent or grandparent xpath command as this would fetch me only 1 or 2 nodes above & it would be rigid & not dynamic enough . So irrespective of any level in the hierarchy I want to fetch the topmost root node
Can someone help me in deriving a way to achieve the same
Now when I am processing every node I need the reference to the root node everytime. Something like
when I m in "Dadar" I need to identify the top most root node value which is "India"
so its like
Root Parent is India for all the child elements under India.
The problem is I am only getting Maharashtra as the topmost root for all the nodes where as in case of Karantaka, Bangalore & MGRoad the top most root node is Karnataka.
The problem is I am only getting Maharashtra as the topmost root for all the nodes where as in case of Karantaka, Bangalore & MGRoad the top most root node is Karnataka.