Xpath条件得到父

时间:2014-10-03 10:22:40

标签: xml xpath

这是我的xml:

<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 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

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

基本上在XPath之上查找<person>元素,<weight>后代等于80,然后从<person>获取<firstname>元素。