xpath表达式未返回正确的信息

时间:2017-05-27 13:59:14

标签: xml xslt xpath

我需要帮助才能找到XPATH表达式,该表达式将检索" Home"的地址编号。网站元素。

<?xml version="1.0" encoding="UTF-8"?>
<location>
<name>
    <site>Work</site>
    <address>4589</address>
</name>
<name>
    <site>Home</site>
    <address>234</address>
</name>
<name>
    <site>Store</site>
    <address>58</address>
</name>
<name>
    <site>School</site>
    <address>712</address>
</name>
</location>

我尝试了这个,但它不起作用:

/location/name[site:"Home"]/address

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:1)

您接近纠正XPath。尝试将:替换为=,如下所示:

/location/name[site="Home"]/address

这将返回address元素。如果您要检索address值,请将/text()添加为

/location/name[site="Home"]/address/text()