Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPATH - local-name question

Status
Not open for further replies.

beefeater267

Programmer
Apr 6, 2005
79
Hi,

have the following statement:
xmlDoc.SelectSingleNode("//*[local-name() = 'item']");

Now, that selects a single node 'item'.... however, there are multiple items with attributes. How can i constrain it? I would like to select item whos name="a"

Example:
<item name="a">xxx</item>
<item name="b">yyy/item>

I couldn't figure out how to do this . Thanks
 
You don't need to use local-name(). Try:
Code:
xmlDoc.SelectSingleNode("//item[@name='a']");
Also, its better to specify the path directly where possible. // is very inefficient.
 
i do need to use local-path b/c i have multiple namespaces.... but anyways, how can i contrain the result while using local path?
 
OK, fair enough:
Code:
xmlDoc.SelectSingleNode("//*[local-name() = 'item' and @name = 'a']");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top