0

I've got this partial XML

 <Events>
   <Properties>
     <Property Descriptor="1">VALUE1</Property>
     <Property Descriptor="2">FOO</Property>
     <Property Descriptor="3">BAR</Property>
     </Properties>
   <Properties>
     <Property Descriptor="1">VALUE2</Property>
     <Property Descriptor="2">NO</Property>
     <Property Descriptor="3">NOTHINGHERE</Property>
   </Properties>
 </Events>

Hi can I query the first occurrence of Property Descriptor="3" when Property Descriptor="2" = "FOO"? Result here should be BAR

I tried //Properties/Property[@Descriptor="3"][..//Property[@Descriptor="2"] = "FOO"] but it's now working.

1 Answer 1

3

can I query the first occurrence of Property Descriptor="3" when Property Descriptor="2" = "FOO"?

/Events/Properties[Property[@Descriptor = '2'] = 'FOO']/Property[@Descriptor = '3'][1]

And in more detail:

/Events/Properties                    Look for a Properties element
[Property                             but only if it has a Property element
[@Descriptor = '2'] = 'FOO']          but only if its Descriptor attribute equals 2 and
                                      its textual content is "FOO"
/Property[@Descriptor = '3']          for that Properties element look for a child element
                                      called Property where the Descriptor attribute equals 3
[1]                                   thereof return the first occurrence
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.