简体   繁体   中英

Querying XML content within an element

I have an odd XML document that I have to query. Its from the Weather.gov output. The information I'd like to query within is under: /Enelope/Body/NDFDgenResponse/dwmlOut. Its a converted form of XML. Is it possible to query individual elements under that value, or will I have to post process it to query within it? My suspicion is that I'll have to post process.

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:NDFDgenResponse xmlns:ns1="http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl">
            <dwmlOut xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;dwml version=&quot;1.0&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd&quot;&gt;
  &lt;head&gt;
    &lt;product srsName=&quot;WGS 1984&quot; concise-name=&quot;glance&quot; operational-mode=&quot;official&quot;&gt;
      &lt;title&gt;NOAA&apos;s National Weather Service Forecast at a Glance&lt;/title&gt;
      &lt;field&gt;meteorological&lt;/field&gt;
      &lt;category&gt;forecast&lt;/category&gt;
      &lt;creation-date refresh-frequency=&quot;PT1H&quot;&gt;2012-06-26T19:09:06Z&lt;/creation-date&gt;
    &lt;/product&gt;
    &lt;source&gt;
      &lt;more-information&gt;http://graphical.weather.gov/xml/&lt;/more-information&gt;
      &lt;production-center&gt;Meteorological Development Laboratory&lt;sub-center&gt;Product Generation Branch&lt;/sub-center&gt;&lt;/production-center&gt;
      &lt;disclaimer&gt;http://www.nws.noaa.gov/disclaimer.html&lt;/disclaimer&gt;
      &lt;credit&gt;http://www.weather.gov/&lt;/credit&gt;
      &lt;credit-logo&gt;http://www.weather.gov/images/xml_logo.gif&lt;/credit-logo&gt;
      &lt;feedback&gt;http://www.weather.gov/feedback.php&lt;/feedback&gt;
    &lt;/source&gt;
  &lt;/head&gt;
  &lt;data&gt;
    &lt;location&gt;

..... </conditions-icon> </parameters> </data> </dwml>

This is a working example of pure XPath 3.0:

//dwmlOut/parse-xml(text())/dwml/head/product/title/text()

Of course, your xpath processor has to support version 3.0 which zorba for example does:

play with it online

With pure XPath probably not. But if you invoke XPath from any other language, you can select that node first into a string type variable, then parse that string as another xml document and use a second XPath expression to select nodes from inside. it

Even if it's possible using pure XPath, this two-step approach is definitely a lot easier to code, test and maintain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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