Given this XML, what XPath returns all elements whose prop
attribute contains Foo
(the first three nodes):
<bla>
<a prop="Foo1"/>
<a prop="Foo2"/>
<a prop="3Foo"/>
<a prop="Bar"/>
</bla>
Given this XML, what XPath returns all elements whose prop
attribute contains Foo
(the first three nodes):
<bla>
<a prop="Foo1"/>
<a prop="Foo2"/>
<a prop="3Foo"/>
<a prop="Bar"/>
</bla>
try this:
//a[contains(@prop,'foo')]
that should work for any "a" tags in the document
Or:
Or:
Dissected:
The Axis - search through every node underneath and the node itself. It is often better to say this than //. I have encountered some implementations where // means anywhere (decendant or self of the root node). The other use the default axis.
The Tag - a wildcard match, and /bla/a is an absolute path.
The condition within [ ]. @prop is shorthand for attribute::prop, as attribute is another search axis. Alternatively you can select the first 3 by using the position() function.
For the code above... //*[contains(@prop,'foo')]