2

I have the following xml and want to get the attribute (identifier='content') value for the attribute (identifier='id') with id 510 with the help of xpath.

<product id='1'> <row='1'> <attribute identifier='id'>510</attribute> <attribute identifier='content'>Test 1</attribute> </row> <row='2'> <attribute identifier='id'>100</attribute> <attribute identifier='content'>Test 2</attribute> </row> ... </product> 

I tried it with:

product[@id='1']/row/attribute[@identifier='id' and text()='510'] 

But as I already know this returns only the content of the attribute with identifier='id'. How to get the value of identifier='content' where identifier 'id'= 510?

Thanks for any help.

1
  • 1
    This is no XML, something's very wrong with your <row/> elements. Commented Feb 17, 2014 at 14:30

1 Answer 1

4

You're looking for the value of the attribute element named content for a row that has an id of 510:

//product[@id='1']/row[attribute[@identifier='id'] = '510']/attribute[@identifier='content'] 

The nested predicate selects attribute elements whose identifier is id and checks whether any of them has the value 510.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.