|
-
Aug 31st, 2007, 06:37 AM
#1
Thread Starter
PowerPoster
XPath
trying to extract all the child nodes where the rootnode is called "Abc"
xml:
<role>
<name>"ABC"</name>
<values id=1>
<value>123</value>
<stuff>asdasdasd</stuff>
</values>
<values id=2>
<value>123</value>
<stuff>asdfdffsdfsdasdasd</stuff>
</values>
</role>
how can I use XPath to return me all nodes from a root node called "ABC"?
-
Aug 31st, 2007, 07:29 AM
#2
I wonder how many charact
Re: XPath
Assuming role is under the root node and the nodes you want to select...
"/role[name=ABC]"
Haven't tested it, but that's my guess..
-
Aug 31st, 2007, 09:26 AM
#3
Re: XPath
Just need some quotes around ABC.
//role[name='ABC']
-
Aug 31st, 2007, 09:30 AM
#4
Thread Starter
PowerPoster
Re: XPath
hmm. still need to get a hang of this. Actually i mis typed the xml doc. should be:
<someRootNode>
<role>
<name>"ABC"</name>
<values id=1>
<value>123</value>
<stuff>asdasdasd</stuff>
</values>
<values id=2>
<value>123</value>
<stuff>asdfdffsdfsdasdasd</stuff>
</values>
</role>
</someRootNode>
-
Aug 31st, 2007, 09:46 AM
#5
Re: XPath
That's what we were assuming. The above should work for that.
c# Code:
XmlDocument xd = new XmlDocument();
xd.Load(@"c:\test\test.xml");
XmlNode nod = xd.SelectSingleNode("//role[name='ABC']");
if (nod != null)
{
MessageBox.Show(nod.InnerXml);
}
-
Aug 31st, 2007, 10:13 AM
#6
Thread Starter
PowerPoster
Re: XPath
what about selecting ALL nodes where the node name is "ABC" - i want to select all nodes in that node
so..
<someRootNode>
<role>
<name>"ABC"</name>
<values id=1>
<value>123</value>
<stuff>asdasdasd</stuff>
</values>
<values id=2>
<value>123</value>
<stuff>asdfdffsdfsdasdasd</stuff>
</values>
</role>
</someRootNode>
should get me the values for valueid1 and valueid2 and valueidX etc...
-
Aug 31st, 2007, 10:22 AM
#7
I wonder how many charact
Re: XPath
So you want to select all <value> nodes where the outtermost containing <role> node contains a <name> node whose value is 'ABC'?
-
Aug 31st, 2007, 10:31 AM
#8
I wonder how many charact
Re: XPath
XmlNodeList nodelist = xd.DocumentElement.SelectNodes("//role/values[value=123]");
-
Aug 31st, 2007, 10:40 AM
#9
Re: XPath
If you want to check for the ABC name first you can try something like this:
//role[name='ABC']/values
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|