访问现有属性返回null [英] accessing existing attribute returns null

查看:111
本文介绍了访问现有属性返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面的表达式以从下面的xml文件中检索信息,但是返回的结果是空的,并且索引出来。

i wrote the below expression to retrieve info from the below xml file, but the returned results is null and index out of bound.

请让我知道如何从该元素检索数据:

please let me know how to retrieve data from this element:

 <ele k="maxspeed:zone" v="60"/>

表达

"//node[@lat='53.0337395'] [@lon='8.8489255']/following-sibling/following-   
sibling::ele[1]/@v"

xml

<?xml version='1.0' encoding='utf-8' ?>
<osm>
<node id="25779111" lat="53.0334062" lon="8.8461545"/>
<node id="25779112" lat="53.0338904" lon="8.846314"/>
<node id="25779119" lat="53.0337395" lon="8.8489255"/>
<tag k="maxspeed" v="30"/>
<tag k="maxspeed:zone" v="yes"/>
<ele k="maxspeed:zone" v="60"/>
<node id="25779114" lat="53.334062" lon="8.841545"/>
<node id="25779117" lat="53.338904" lon="8.84614"/>
<node id="25779110" lat="53.33795" lon="8.489255"/>
<tag k="maxspeed" v="32"/>
<tag k="maxspeed:zone" v="no"/>
</osm>


推荐答案

你几乎在那里 - 你需要添加 :: tag [1] 到第一个 follow-sibling ,像这样:

You are almost there - you need to add ::tag[1] to the first following-sibling, like this:

"//node[@lat='53.0337395'] [@lon='8.8489255']/following-sibling::tag[1]/following-sibling::ele[1]/@v"

这将检索 Attribute ='v = 60'

这篇关于访问现有属性返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆