Metro Application How to Read XML API?(Metro 应用程序如何读取 XML API?)
问题描述
好的,所以我正在尝试学习如何使用 XAML 以及如何使用 Visual Studio 11 Developer Preview 构建新的 Windows Metro 应用程序.
Ok so I am trying to learn how to work with XAML and how to build new windows metro applications using Visual Studio 11 Developer Preview.
虽然我不知道如何像使用 C# 一样读取 XML 文件,但我遇到了一个问题.例如,这是我过去的做法.
I have a problem though I don't know how to read XML files the same way I use to using C#. For example here is how I did it in the past.
private void Button_Click(object sender, RoutedEventArgs e)
{
string UrlString = "http://v1.sidebuy.com/api/get/73d296a50d3b824ca08a8b27168f3b85/?city=nashville&format=xml";
XmlTextReader reader = new XmlTextReader(UrlString);
XmlNodeType type;
while (reader.Read())
{
type = reader.NodeType;
if ((type == XmlNodeType.Element) && (reader.Name == "highlights"))
{
reader.Read();
if (reader.Value != "" && reader.Value != null)
{
listBox1.Items.Add(reader.Value);
}
}
}
}
但这在我的 Metro 应用程序中不起作用.我需要知道如何为地铁做到这一点.显然 XmlTextReader 不再有效.有什么代码或建议吗?
But this won't work in my metro application. I need to know how to do this for metro. Apparently XmlTextReader is no longer valid. Any code or suggestions?
谢谢
推荐答案
你可以使用 XmlDocument.LoadFromUriAsync.这也应该使您的代码更简单.
You can use XmlDocument.LoadFromUriAsync. This should also make your code a lot simpler.
private async void Button_Click(object sender, RoutedEventArgs e)
{
string UrlString = "http://v1.sidebuy.com/api/get/73d296a50d3b824ca08a8b27168f3b85/?city=nashville&format=xml";
var xmlDocument = await XmlDocument.LoadFromUriAsync(UrlString);
//read from xmlDocument for your values.
}
根据注释修复代码.
这篇关于Metro 应用程序如何读取 XML API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Metro 应用程序如何读取 XML API?


- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01