[英]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.