开发者

XML - Header contains Illegal character

开发者 https://www.devze.com 2023-03-14 06:37 出处:网络
I\'m trying to consume a WebService for getting the current Weather for places i开发者_如何学Cn The Netherlands.

I'm trying to consume a WebService for getting the current Weather for places i开发者_如何学Cn The Netherlands.

        public void GetWeather()
    {
        net.webservice.GlobalWeather.GlobalWeather GlobalWeatherService = new net.webservice.GlobalWeather.GlobalWeather();
        string SoapResult = GlobalWeatherService.GetWeather(Location, "Netherlands");

        XmlDocument XmlDoc = new XmlDocument();
        XmlDoc.Load(SoapResult);
        XmlNodeList XmlForecast = XmlDoc.GetElementsByTagName("CurrentWeather");
    }

The webservice posts back a XML file as a string

    <?xml version="1.0" encoding="utf-16"?>
<CurrentWeather> 
<Location>Amsterdam Airport Schiphol, Netherlands (EHAM) 52-18N 004-46E -2M</Location>
<Time>Jun 20, 2011 - 06:25 AM EDT / 2011.06.20 1025 UTC</Time> 
<Wind> from the SW (220 degrees) at 9 MPH (8 KT):0</Wind> 
<Visibility> greater than 7 mile(s):0</Visibility> 
<SkyConditions> partly cloudy</SkyConditions> 
<Temperature> 62 F (17 C)</Temperature> 
<DewPoint> 51 F (11 C)</DewPoint> 
<RelativeHumidity> 67%</RelativeHumidity> 
<Pressure> 29.88 in. Hg (1012 hPa)</Pressure> 
<Status>Success</Status> 
</CurrentWeather>

But when I try to load result in a XmlDocument I get an ArguementException (Illegal characters in path) on XmlDoc.Load(SoapResult);

What am I doing wrong?


XmlDocument.Load(), loads the XML document from the specified URL, for the file containing the XML document to load. The URL can be either a local file or an HTTP URL (a Web address).

Throws ArgumentException if filename is a zero-length string, contains only white space, or contains one or more invalid characters.

Use LoadXml() instead.


XmlDoc.Load takes a filepath as input param and not the actual string

maybe you need to load this GlobalWeatherService.GetWeather(Location, "Netherlands")

As Filburt suggests use XmlDoc.LoadXml

0

精彩评论

暂无评论...
验证码 换一张
取 消