如何从url C#中读取xml

时间:2014-12-01 09:26:42

标签: c# xml

我无法从http://158.58.185.214/Applications/Operator/Files/Data/Bus/CityList.xml读取xml字符串,我认为编码是问题,请帮助解决。

我的代码是:

        string url = "http://158.58.185.214/Applications/Operator/Files/Data/Bus/CityList.xml";
        WebClient client = new WebClient();
        string xml = client.DownloadString(url);

但是xml字符串是:

‹      í½`I–%&/mÊ{JõJ×àt¡€`$Ø@ìÁˆÍæ’ìiG#....

1 个答案:

答案 0 :(得分:-1)

你的问题可以像这样解决

使用System.Xml;

String URLString = " http://localhost/books.xml";
XmlTextReader reader = new XmlTextReader (URLString);

    while (reader.Read()) 
    {
    // Do some work here on the data.
     Console.WriteLine(reader.Name);
    }
Console.ReadLine();

请参阅:https://support.microsoft.com/kb/307643/en-us