1

I am trying to come up with an XPath to the following XML:

<A>
   <Target attr1="foo" attr2="bar"/>
   <B>
      <Target attr1="forest" attr2="gump"/>
      <C>
          <Target attr1="foo" attr2="aDifferentKindOfBar"/>    
      </C>
      <C/>
   </B>
</A>

It should give me the value of attribute named "attr2" for all elements Target that have an attribute "attr1" with value "foo".

So in my example I would like to get "bar" and "aDifferentKindOfBar" but not "gump".

I came as far as:

//Target[@attr1='foo']

But I can't figure out how to get the navigation to the attribute "attr2".

1 Answer 1

3

Just add the next step to the path:

//Target[@attr1='foo']/@attr2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.