0

我有这个肥皂响应,但我的代码没有读取 GetLatestReadingByMeterNoResult 孩子。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
  <soapenv:Body>
    <GetLatestReadingByMeterNoResponse xmlns="http://www.multispeak.org/Version_3.0">
     <GetLatestReadingByMeterNoResult objectID="112199498" utility="xxxxx">
      <meterNo>112199498</meterNo> 
      <deviceID>112199498</deviceID> 
      <readingDate>2013-02-27T17:00:00.000Z</readingDate> 
      <posKWh>8406</posKWh> 
      <kW>15.508</kW> 
      <kWDateTime>2013-02-27T17:00:00.000Z</kWDateTime> 
      </GetLatestReadingByMeterNoResult>
     </GetLatestReadingByMeterNoResponse>
  </soapenv:Body>
</soapenv:Envelope>

代码:

XmlDocument resultXml = new XmlDocument();
XmlNamespaceManager mgr = new XmlNamespaceManager(resultXml.NameTable);
mgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
mgr.AddNamespace("", "http://www.multispeak.org/Version_3.0");
resultXml.LoadXml(soapResult);
XmlNodeList nodeList = resultXml.SelectNodes("//GetLatestReadingByMeterNoResult", mgr);

nodeList 不返回任何节点

4

1 回答 1

5

试试这个:

mgr.AddNamespace("multi", "http://www.multispeak.org/Version_3.0");
resultXml.LoadXml(soapResult);
XmlNodeList nodeList = resultXml.SelectNodes("//multi:GetLatestReadingByMeterNoResult", mgr);

即使在处理默认命名空间时,在代码中使用 XPATH 时也需要使用前缀。

于 2013-02-27T19:53:14.353 回答