0

我有这个部分 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>

嗨,当 Property Descriptor="2" = "FOO" 时,我可以查询 Property Descriptor="3" 的第一次出现吗?这里的结果应该是BAR

我试过//Properties/Property[@Descriptor="3"][..//Property[@Descriptor="2"] = "FOO"]了,但现在可以了。

4

1 回答 1

3

当 Property Descriptor="2" = "FOO" 时,我可以查询 Property Descriptor="3" 的第一次出现吗?

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

更详细地说:

/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
于 2014-11-16T23:10:09.397 回答