简体   繁体   English

如何使用C#Windows Phone 8.1从URL读取XML数据

[英]How to read XML data from a URL by using C# Windows Phone 8.1

I write this code block on my windows 8.1 project it's working. 我在正在运行的Windows 8.1项目上编写此代码块。 But didn't work on my windows phone 8.1 project 但是在我的Windows Phone 8.1项目上不起​​作用

  private void Page_Loaded(object sender, RoutedEventArgs e)
    {

        Uri url = new Uri("http://www.tcmb.gov.tr/kurlar/today.xml");
        XDocument xml = XDocument.Load(url.ToString());
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xml.ToString());
    }

First of all, I downloaded the XML and Windows Phone doesn't support "ISO-8859-9". 首先,我下载了XML,Windows Phone不支持“ ISO-8859-9”。

Second, in order to use XDocument, you need to download the file and send the stream as a parameter to the Load method. 其次,为了使用XDocument,您需要下载文件并将流作为参数发送到Load方法。

Here's an example: 这是一个例子:

public void LoadXML()
{
    HttpClient client = new HttpClient();
    var httpResponseMessage = await client.GetAsync(new Uri("http://thewindev.net/post-sitemap.xml"));
    if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
    {
        var xmlStream = await httpResponseMessage.Content.ReadAsStreamAsync();
        XDocument xml = XDocument.Load(xmlStream);
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xml.ToString());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Windows Phone 8.1中的XML文件读取数据 - Read data from XML file in Windows Phone 8.1 如何使用 Visual C# 从 URL 读取 XML 数据 - How to read XML data from a URL by using Visual C# 如何从 URL 获取 Json 对象,Windows Phone 8.1 (C#) - How can I get my Json object from URL, Windows Phone 8.1 (C#) 在Windows Phone 8.1 C#中保存数据 - Save data in windows phone 8.1 c# 如何从Windows Phone,C#中的xmldocument中获取(读取)数据 - how to get(read) data from xmldocument in windows phone, c# LongListSelector C#-如何从分组的数据列表中以字符串形式获取SelectedItem-Windows Phone Silverlight 8.1 - LongListSelector C# - How to get SelectedItem as string from grouped data list - Windows Phone Silverlight 8.1 如何在C#中从中心部分数据模板Windows Phone 8.1访问网格视图 - How to Access Grid View from hub section Data Template Windows phone 8.1 in C# 如何在WinRT-apps(Javascript,C#)中区分Windows Phone 8.1与Windows 8.1? - How to distinguish Windows Phone 8.1 from Windows 8.1 in WinRT-apps (Javascript, C#)? Windows Phone 8.1 XDocument xml序列化C# - Windows phone 8.1 XDocument xml serialization C# 如何在C#Windows Phone中读取元素xml的属性? - How to read the attribute of an element xml in C# Windows Phone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM