2014-10-03 49 views
0

这里是我的xml:Xpath的条件获取父

<people> 
<person id="0001"> 
    <firstname>Christopher</firstname> 
    <lastname>Shaw</lastname> 
    <birthdate>1975-02-23T21:24:46.000+02:00</birthdate> 
    <healthprofile> 
     <lastupdate>2014-09-30T10:38:07.000+02:00</lastupdate> 
     <weight>84</weight> 
     <height>2.13</height> 
     <bmi>18.51</bmi> 
    </healthprofile> 
</person> 
<person id="0002"> 
    <firstname>Brian</firstname> 
    <lastname>Tooley</lastname> 
    <birthdate>1987-10-19T08:18:59.000+02:00</birthdate> 
    <healthprofile> 
     <lastupdate>2014-09-30T10:38:07.000+02:00</lastupdate> 
     <weight>98</weight> 
     <height>2.17</height> 
     <bmi>20.81</bmi> 
    </healthprofile> 
</person> 
</people> 

我想用XPath是提取其重量等于80例如那些用户的名字做什么。我无法得到这个工作。

回答

1

你可以尝试这样的事情:

/people/person[healthprofile/weight='80']/firstname 

基本上上面的XPath找等于80<person>元件,其具有<weight>后代,然后从<person>得到<firstname>元素。