1
<?xml version="1.0" encoding="UTF-8"?>
<a>
   <b>
      <c>110</c>
      <d>periodendyear="2019"</d>
      <e>
         <f>
            <code>xyz</code>
            <value>54</value>
         </f>
      </e>
      <e>
         <f>
            <code>xy</code>
            <value>6</value>
         </f>
      </e>
   </b>
</a>

How would you select all the a, d and code and value elements that are children of b elements?

Basically, something like:

//b | //f
0

2 Answers 2

1

How would you select all the a, d and code and value elements that are children of b elements?

Note that there are no code and value children of b elements, so I'll assume that you meant descendants, not just children.

This XPath,

//b//*[self::a or self::d or self::code or self::value]

will select all a, d and code and value elements that are descendants of all b elements anywhere in the document.

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

Comments

0

If you want to select all the c, d, code, value nodes that are descendants of the b node with the single XPath expression try

//b//*[name()=('c', 'd', 'code', 'value')]

1 Comment

Note that =('c', 'd', 'code', 'value') requires XPath 2.0.

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.