XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Sushant PrabhuSubject: 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="22" oid="8">
<node_name>Mumbai</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


Regards

Postnext
James DurningSubject: Get the root node name
Author: James Durning
Date: 16 Nov 2006 11:48 AM
<xsl:value-of select="name(/*)"/>

Not sure if you're using xsl, but the xpath should work in most applications.

Postnext
Sushant PrabhuSubject: Get the root node name
Author: Sushant Prabhu
Date: 16 Nov 2006 06:47 PM
Hi ,

I tried quiet a few techinques but could not get the output as intended.

Here is the sample xml file which we get
*********************************

<node cid="1" oid="2">
<node_name>India</node_name>
<node cid="11" oid="4">
<node_name>Maharashtra</node_name>

<node cid="22" oid="8">
<node_name>Mumbai</node_name>

<node cid="33" oid="8">
<node_name>Dadar</node_name>
</node>
*********************************

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.

Do post your thoughts

Regards

Postnext
James DurningSubject: Get the root node name
Author: James Durning
Date: 17 Nov 2006 09:27 AM
Originally Posted: 17 Nov 2006 09:23 AM
the fragment posted is not valid xml.
Perhaps:
<xsl:value-of select="/*//node_name"/>

If you're using apply-templates to process these nodes, you could have a parameter which keeps track of the 'root' node.

Postnext
Sushant PrabhuSubject: Get the root node name
Author: Sushant Prabhu
Date: 19 Nov 2006 07:58 PM
Hi James,

I tried this solution but it works only for the 1st parent.

Here is what my xml file looks like

****************************************
<node cid="11" oid="4">
<node_name>Maharashtra</node_name>

<node cid="22" oid="8">
<node_name>Mumbai</node_name>

<node cid="33" oid="8">
<node_name>Dadar</node_name>
</node> --------

****************************************

Now this is another node

<node cid="11" oid="4">
<node_name>Karnataka</node_name>

<node cid="22" oid="8">
<node_name>Bangalore</node_name>

<node cid="33" oid="8">
<node_name>MGRoad</node_name>
</node>

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.


Regards

Posttop
Sushant PrabhuSubject: Get the root node name
Author: Sushant Prabhu
Date: 20 Nov 2006 12:17 AM
Hi James,

I tried this solution but it works only for the 1st parent.

Here is what my xml file looks like

****************************************
<node cid="11" oid="4">
<node_name>Maharashtra</node_name>

<node cid="22" oid="8">
<node_name>Mumbai</node_name>

<node cid="33" oid="8">
<node_name>Dadar</node_name>
</node> --------

****************************************

Now this is another node

<node cid="11" oid="4">
<node_name>Karnataka</node_name>

<node cid="22" oid="8">
<node_name>Bangalore</node_name>

<node cid="33" oid="8">
<node_name>MGRoad</node_name>
</node>

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.


Regards

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.