In answering this question, I came across a situation that I don't understand. The OP was trying to load XML from the following location: http://www.google.com/ig/api?weather=12414&hl=it
The obvious solution is:
string m_strFilePath = "http://www.google.com/ig/api?weather=12414&hl=it";
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load(m_strFilePath); //Load NOT LoadXml
However this fails with
XmlException : Invalid character in the given encoding. Line 1, position 499.
It seems to be choking on the à
of Umidità
.
OTOH, the following works fine:
var m_strFilePath = "http://www.google.com/ig/api?weather=12414&hl=it";
string xmlStr;
using(var wc = new WebClient())
{
xmlStr = wc.DownloadString(m_strFilePath);
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);
I'm baffled by this. Can anyone explain why the former fails, but the latter works fine?
Notably, the xml declaration of the document omits an encoding.