TomT
TomT

Reputation: 319

XPath Wildcard -- Any Node Name, Must have Specific Attribute Value

I am having difficulty figuring out an XPath query that would allow me to return nodes based on the value of the Program attribute in the example below. For example, I would like to be able to search all nodes for a value of the Program attribute = "011.pas". I tried /Items/*[Program="012.pas"] and also /Items/Item*[Program="01.pas"] but neither works. What is the correct expression?

<Items>
 <Item0 Program="01.pas"></Item0>
 <Item1 Program="011.pas"></Item1>
</Items>

Upvotes: 0

Views: 402

Answers (2)

ikken
ikken

Reputation: 563

Try this :

/items/*[@Program='011.pas']

Upvotes: 1

Martin Honnen
Martin Honnen

Reputation: 167516

The attribute is selected with @Program, the child elements of the Items element with /Items/*, so you want /Items/*[@Program = '011.pas'].

Upvotes: 2

Related Questions