i wrote beloww code retrive value of attribuet v in element tag specifyin lat , lon values shown below. think mistake related how use && operator in xpath expression, because when used
string expr0 = "//node[@lat='53.334062']/following-sibling::tag[1]/@v"; i receive expected value, when uesd below posted expression, system crashs
but @ run time, program crashs , shows below error message.
code:
string expr0 = "//node[@lat='53.334062' && @lon='8.841545']/following-sibling::tag[1]/@v"; xpath.compile(expr0); string s = (string) xpath.evaluate(expr0, document, xpathconstants.string); system.out.println(s); 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"/> <node id="25779114" lat="53.334062" lon="8.841545"/> <node id="25779117" lat="53.038904" lon="8.84614"/> <node id="25779110" lat="53.033795" lon="8.489255"/> <tag k="maxspeed" v="32"/> <tag k="maxspeed:zone" v="yes"/> </osm> error:
exception in thread "main" javax.xml.transform.transformerexception: zusätzliche ungültige tokens: '&&', '[', '@', 'lon', '=', ''8.841545'', ']', '/', 'following-sibling', '::', 'tag', '[', '1', ']', '/', '@', 'v' @ com.sun.org.apache.xpath.internal.compiler.xpathparser.error(unknown source) @ com.sun.org.apache.xpath.internal.compiler.xpathparser.initxpath(unknown source) @ com.sun.org.apache.xpath.internal.xpath.<init>(unknown source) @ com.sun.org.apache.xpath.internal.xpath.<init>(unknown source) @ com.sun.org.apache.xpath.internal.jaxp.xpathimpl.compile(unknown source)
the boolean "and" operator in xpath word and, not && (specification)
string expr0 = "//node[@lat='53.334062' , @lon='8.841545']/following-sibling::tag[1]/@v"; alternatively can use 2 predicates:
string expr0 = "//node[@lat='53.334062'][@lon='8.841545']/following-sibling::tag[1]/@v"; this has same effect - predicates apply left right first predicate filters set of node elements have @lat='53.334062', second filters that set have @lon='8.841545'.
Comments
Post a Comment