accessing existing attribute returns null

2019-09-08 14:52发布

问题:

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"/>

expression:

"//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>

回答1:

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"

This retrieves Attribute='v="60"'