1

I need to get the C node that has the field (name = p and value = 4)

How to get this without using index?

<A>
    <B>
        <C>
            <field name="p" value="1"/>
            <field name="q" value="2"/>
        </C>
        <C>
            <field name="p" value="3"/>
            <field name="q" value="4"/>
        </C>
    </B>
</A>
3
  • Possible duplicate of XPath to select Element by attribute value Commented May 17, 2019 at 8:50
  • there is no node name = p and value = 4 on your example of xml file? Commented May 17, 2019 at 9:09
  • @KunduK i was referring to <field name="q" value="4"/> Commented May 17, 2019 at 9:18

1 Answer 1

0

Try the following Xpath.

//field[@name="q"][@value="4"]/..
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the suggestion. however I was trying to get the <C> node that has <field name="q" value="4"/>. (editing my question now)
Edited Try now.
this did the trick //C//field[@name="q"][@value="4"]/.. pls add this to your solution, so that i can mark it as the answer
Your question was not clear to me earlier.If you asked that you want get parent tag of given child tag it would have been better.Updated it thanks.

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.