我有一个奇怪的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"><?xml version="1.0"?>
<dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">
<head>
<product srsName="WGS 1984" concise-name="glance" operational-mode="official">
<title>NOAA's National Weather Service Forecast at a Glance</title>
<field>meteorological</field>
<category>forecast</category>
<creation-date refresh-frequency="PT1H">2012-06-26T19:09:06Z</creation-date>
</product>
<source>
<more-information>http://graphical.weather.gov/xml/</more-information>
<production-center>Meteorological Development Laboratory<sub-center>Product Generation Branch</sub-center></production-center>
<disclaimer>http://www.nws.noaa.gov/disclaimer.html</disclaimer>
<credit>http://www.weather.gov/</credit>
<credit-logo>http://www.weather.gov/images/xml_logo.gif</credit-logo>
<feedback>http://www.weather.gov/feedback.php</feedback>
</source>
</head>
<data>
<location>
..... &LT; /条件图标&GT; &LT; /参数&GT; &LT; /数据&GT; &LT; / DWML&GT;
答案 0 :(得分:3)
这是纯XPath 3.0的一个工作示例:
//dwmlOut/parse-xml(text())/dwml/head/product/title/text()
当然,您的xpath处理器必须支持版本3.0,例如zorba:
答案 1 :(得分:1)
纯XPath可能不行。但是,如果从任何其他语言调用XPath,则可以先将该节点选择为字符串类型变量,然后将该字符串解析为另一个xml文档,并使用第二个XPath表达式从内部选择节点。它
即使可以使用纯XPath,这种两步法也更容易编码,测试和维护。