tags:

views:

23

answers:

1

I'm thinking this is a very simple xpath question .. I'm just not sure why my xpath isn't working.

Here's what my XML looks like

<A>
  <B>foo</B>
</A>

<C>
  <A>
    <B>foo</B>
  </A>
</C>

Now .. I want to grab all "A" elements which contain a "B" with contained text "foo".

+3  A: 
//A[B[text()='foo']]
  • //A matches all As
  • //A[B] that have a B as a child
  • //A[B[text()='foo']] which contains foo as text.

I suggest to read the XPath tutorial at w3chools.com

Felix Kling
Needs to be the direct descendant.
desau
@desau: Ok, updated it.
Felix Kling
Ninja edited... I believe that's `[B]` not `[/B]`.
John Kugelman
@John Kugelman: You are right, thank you!
Felix Kling
Bingo! You two nailed it. I thought I'd tried everything .. I was at the point of calling it a bug in the xpath library .. but it was just incorrect xpath. Thanks!
desau