繁体   English   中英

Xpath:获取节点属性

[英]Xpath: getting node attribute

我正在尝试解析一个看起来像这样的XML文件:

<body>
<predictions>
<direction>
    <prediction epochTime="1400182631361" seconds="1109" minutes="18" isDeparture="false" dirTag="N__OB1" vehicle="1495" vehiclesInConsist="2" block="9708" tripTag="6041030"/>
    <prediction epochTime="1400182942181" seconds="1420" minutes="23" isDeparture="false" dirTag="N__OB1" vehicle="1515" vehiclesInConsist="2" block="9709" tripTag="6041031"/>
    <prediction epochTime="1400183687220" seconds="2165" minutes="36" isDeparture="false" dirTag="N__OB1" vehicle="1481" vehiclesInConsist="2" block="9710" tripTag="6041032"/>
    <prediction epochTime="1400183966372" seconds="2444" minutes="40" isDeparture="false" affectedByLayover="true" dirTag="N__OB1" vehicle="1520" vehiclesInConsist="2" block="9712" tripTag="6041033"/>
    <prediction epochTime="1400184566372" seconds="3044" minutes="50" isDeparture="false" affectedByLayover="true" dirTag="N__OB1" vehicle="1430" vehiclesInConsist="2" block="9713" tripTag="6041034"/>
</direction>

</predictions>
</body>

我想用Xpath(通过“/ body / predictions / direction / @ seconds”)提取每个prediction节点内的所有seconds属性,但它不会为我返回任何内容。 有任何想法吗?

试试这个:

//prediction/@seconds

double /选择所有行,而@选择所需的属性。 您的查询没有返回任何内容,因为您正在尝试获取当前不存在的directionseconds属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM