views:

70

answers:

1

When I try to load a xmlfile which has the '%' in an attribute, I get a XmlException at the position of the '%'. See at the Example in the tag 'humidity'

<current_conditions>
  <condition data="Klar"/>
  <temp_f data="63"/>
  <temp_c data="17"/>
  <humidity data="Feuchtigkeit: 30 %"/>
  <icon data="/ig/images/weather/sunny.gif"/>
  <wind_condition data="Wind: W mit 34 km/h"/>
</current_conditions>

Loading the XmlDocument with xmlDoc:

private void ParseXML(string url) {
  XmlDocument doc = new XmlDocument();
  doc.Load(url);
}
A: 

This is an encoding problem.
You can work around it by using WebClient, like this:

private void ParseXML(string url) {
    string xmlSource;
    using(WebClient wc = new WebClient())
        xmlSource = wc.DownloadString(url);

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xmlSource);
}

(Tested)

SLaks
Except for the fact that the WebClient class doesn't exist in the CF.
ctacke
@SLaks: Thanks for the hint. I'm using the WebRequest wc = HttpWebRequest.Create(url); for now. But I wonder if there is a way to change the Encoding in the XmlDocument itself?
chriszero
No, there isn't.
SLaks