Metro应用如何阅读XML

Metro应用如何阅读XML

本文介绍了Metro应用如何阅读XML API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 好了,所以我想学习如何使用XAML工作和如何使用Visual Studio 11开发者预览版,以建立新的窗口城域应用。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.我有一个问题,虽然我不知道如何读取XML文件,我用它来使用C#以同样的方式。例如,下面是我做到了过去。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); } } } } 不过,这会不会在我的地铁应用程序。我需要知道如何为地铁做到这一点。显然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. } 编辑:根据评论固定码 Fixed code based on comment. 这篇关于Metro应用如何阅读XML API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 22:28