|
-
May 7th, 2012, 07:18 PM
#2
Re: Find Specific XML Node value
Yes - using XPATH you can search for specific nodes. I believe something like that would work:
Code:
XmlDocument doc;
//load your document to doc here...
XmlNode node = doc.SelectSingleNode("test/query/inputParameters/" +
"parameter[parameterValue/text() = IDNumber]/parameterValue");
Console.WriteLine(node.InnerText);
Your probably wonder what the XPATH query I wrote does.
Well, here's a translation of this XPath query to plain English:
-Look for an XML element named "test".
-Then look for a child of "test" named "query".
-Then look for a child of "query" named "inputParameters".
-Then look for a "parameter" child that has a "parameterValue" child, whose text is "IDNumber".
-Return the child named "parameterValue" of this parameter.
Note that if there can be more than one parameters with paramaterName = "IDNumber", you should use the Select method instead of SelectSingleNode.
SelectSingleNode will return the first node that matches your XPATH query, whereas Select will return a collection of all the nodes that match your XPATH query.
In general, if you work with XML files, you should get familiar with XPATH - it's very useful.
Tal.
Last edited by Talikag; May 7th, 2012 at 07:25 PM.
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
|