Alex Rivera | Logout

What is the correct XPath for choosing attributes that contain "foo"?

Asked 2008-09-19T16:11:05.567
223

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>
Edit
Report

2 Answers

6

Have you tried something like:

//a[contains(@prop, "Foo")]

I've never used the contains function before but suspect that it should work as advertised...

answered 2008-09-19T16:16:33.307
6

John C is the closest, but XPath is case sensitive, so the correct XPath would be:

/bla/a[contains(@prop, 'Foo')]
answered 2008-09-19T16:24:45.767

Your Answer