我从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><?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
<Location>Siemreap, Cambodia (VDSR) 13-22N 103-51E 15M</Location>
<Time>Dec 22, 2013 - 01:00 PM EST / 2013.12.22 1800 UTC</Time>
<Wind> Variable at 2 MPH (2 KT):0</Wind>
<Visibility> 4 mile(s):0</Visibility>
<SkyConditions> partly cloudy</SkyConditions>
<Temperature> 66 F (19 C)</Temperature>
<DewPoint> 60 F (16 C)</DewPoint>
<RelativeHumidity> 82%</RelativeHumidity>
<Pressure> 29.91 in. Hg (1013 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather></GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>
Run Code Online (Sandbox Code Playgroud)