小编dev*_*use的帖子

如何使用xPath?

我从Web服务响应中获取了以下xml文件,如何在visual studio中检索喜欢说位置和存储到字符串中的值?我尝试了以下代码:

XmlNode root = wsResponseXmlDoc.DocumentElement;
XmlNode currentWeather = root.SelectSingleNode("/CurrentWeather/Location");
Run Code Online (Sandbox Code Playgroud)

但它给了我'System.NullReferenceException'错误.请帮忙!

 <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetWeatherResponse xmlns="http://www.webserviceX.NET"><GetWeatherResult>&lt;?xml version="1.0" encoding="utf-16"?&gt;
    &lt;CurrentWeather&gt;
      &lt;Location&gt;Siemreap, Cambodia (VDSR) 13-22N 103-51E 15M&lt;/Location&gt;
      &lt;Time&gt;Dec 22, 2013 - 01:00 PM EST / 2013.12.22 1800 UTC&lt;/Time&gt;
      &lt;Wind&gt; Variable at 2 MPH (2 KT):0&lt;/Wind&gt;
      &lt;Visibility&gt; 4 mile(s):0&lt;/Visibility&gt;
      &lt;SkyConditions&gt; partly cloudy&lt;/SkyConditions&gt;
      &lt;Temperature&gt; 66 F (19 C)&lt;/Temperature&gt;
      &lt;DewPoint&gt; 60 F (16 C)&lt;/DewPoint&gt;
      &lt;RelativeHumidity&gt; 82%&lt;/RelativeHumidity&gt;
      &lt;Pressure&gt; 29.91 in. Hg (1013 hPa)&lt;/Pressure&gt;
      &lt;Status&gt;Success&lt;/Status&gt;
    &lt;/CurrentWeather&gt;</GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

c# xml asp.net

0
推荐指数
1
解决办法
91
查看次数

标签 统计

asp.net ×1

c# ×1

xml ×1