0

I need to extract values of elements: price and publisher, given the title of the book from this XML.

<book>
    <title>Burning Tower</title>
    <author>Larry Niven</author>
    <author>Jerry Pournelle</author>
    <publisher>Pocket</publisher>
    <isbn>0743416910</isbn>
    <price>5.99</price>
</book>

How this can be done?

I need to extract attribute name when field name is given. Suppose if I have field name Testing, then I need to extract attribute value for name corresponding to that field.

<RequirementFieldList>
  <field name="SN_Name">Testing</field>
  <field name="Email1">Test1_User</field>
  <field name="Email2">na</field>
  <field name="Email3">na</field>
  <field name="Email4">na</field>
</RequirementFieldList>
1
  • price is inside title or book? Commented Oct 25, 2019 at 7:46

1 Answer 1

1

Using the XPath: book[title='foo']/price will give you the price values of all books with the title "foo". To get the publisher you can just use: book[title='foo']/publisher.

This provides a similar example to yours: https://www.w3schools.com/xml/xml_xpath.asp

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

2 Comments

Thank You so much. Please provide answer of 2nd question which I have added in this question too.
@AnchalSarraf For your second question, simply RequirementFieldList/field[text()="Testing"]/@name

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.