2

照会しなければならない奇妙な XML ドキュメントがあります。その Weather.gov 出力から。照会したい情報は、/Enelope/Body/NDFDgenResponse/dwmlOut の下にあります。変換された形式の XML です。その値の下で個々の要素をクエリすることは可能ですか、それとも後処理してその値内でクエリを実行する必要がありますか? 私の疑いは、プロセスを投稿する必要があるということです。

<?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>

4

2 に答える 2

3

これは、純粋な XPath 3.0 の実際の例です。

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

もちろん、xpath プロセッサはバージョン 3.0 をサポートしている必要があります。たとえば、zorba は次のように機能します。

オンラインで遊ぶ

于 2012-06-27T08:45:18.743 に答える
1

純粋な XPath ではおそらくそうではありません。ただし、他の言語から XPath を呼び出す場合は、最初にそのノードを文字列型の変数に選択してから、その文字列を別の xml ドキュメントとして解析し、2 番目の XPath 式を使用して内部からノードを選択できます。それ

純粋な XPath を使用することが可能であるとしても、この 2 段階のアプローチは、コーディング、テスト、および保守がはるかに簡単であることは間違いありません。

于 2012-06-26T19:55:53.430 に答える