首页 文章

我想使用XPath检索XML属性值

提问于
浏览
0

我想使用XPath搜索XML文件中存在的属性值,例如在您输入“/ ex1 / ex2 / ex3 / text()”的节点值中搜索,但如果我想获取a的值,该怎么办?参数存在于节点中,

让我们考虑从以下XML数据中获取 humidity

<?xml version="1.0" encoding="UTF-8"?>
    -<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <!-- api6.weather.ch1.yahoo.com Thu May 16 06:04:56 PST 2013 -->
     -<channel> 
 <language>en-us</language>
 <ttl>60</ttl> 
<yweather:atmosphere pressure="29.97" visibility="3.73" rising="0" humidity="73"/> <yweather:astronomy sunset="6:41 pm" sunrise="4:59 am"/>
</channel>
</rss>

2 回答

  • 0

    你可以使用 //*/@humidity . 这将为您提供文档中任何位置的所有 humidity 属性节点 .

  • 2

    你会使用 //atmosphere/@humidity . 通过这个XPath syntax教程 .

相关问题