Friday 15 February 2013

xml - Not able to fetch data using xpath which contains encoded special character -



xml - Not able to fetch data using xpath which contains encoded special character -

following xml structure.

<city name="bellmore" > <sitename name="mill pond auto body" > <sitestreet>3000 merrick rd</sitestreet> <zipcode>11710</zipcode> </sitename> <sitename name="sts tire &amp; auto centers" > <sitestreet>chg sunrise hwy</sitestreet> <zipcode>11710</zipcode> </sitename> <sitename name="auto connection" > <sitestreet>2860 sunrise hwy</sitestreet> <zipcode>11710</zipcode> </sitename> <sitename name="perry&#39;s auto" > <sitestreet>1703 newbridge rd</sitestreet> <zipcode>11710</zipcode> </sitename> </city>

i able find info when used next xpath query.

//city[@name='bellmore']/sitename[@name='auto connection']/sitestreet/text()

but when using next xpath query

//city[@name='bellmore']/sitename[@name='perry&#39;s auto']/sitestreet/text()

it not homecoming anything. have converted special characters in xml.

xpath sees parsed xml, need check actual characters rather character references:

//city[@name="bellmore"]/sitename[@name="perry's auto"]

xpath string literals can delimited single or double quotes, if want include single quote character in literal must delimited double quotes.

the thing muddies waters when see examples of xpath expressions beingness used within source code written in host language such java or xslt, characters create xpath look subject quoting rules of host language. illustration above look in java might like:

class="lang-java prettyprint-override">string xpath = "//city[@name=\"bellmore\"]/sitename[@name=\"perry's auto\"]";

or in xslt might either of:

<xsl:value-of select='//city[@name="bellmore"]/sitename[@name="perry&apos;s auto"]' /> <xsl:value-of select="//city[@name=&quot;bellmore&quot;]/sitename[@name=&quot;perry's auto&quot;]" />

the look still contains various single , double quote characters, how characters represented depends on host language.

xml xpath

No comments:

Post a Comment