简体   繁体   English

显示xml文件中的一个项目并将其显示为c#

[英]Displaying one item from an xml file and dispalying it c#

I am creating an app for windows phone and i am searching the lyrics and need to display the data from the xml. 我正在为Windows手机创建一个应用程序,我正在搜索歌词,需要显示xml中的数据。 Now i know how to do this for many items in listbox, but the xml data i receive is only ever going to have one option. 现在我知道如何为列表框中的许多项目执行此操作,但我收到的xml数据只会有一个选项。 http://lyrics.wikia.com/api.php?artist=pharrell%20williams&song=happy&fmt=xml There is an example of the xml i am trying to parse and display. http://lyrics.wikia.com/api.php?artist=pharrell%20williams&song=happy&fmt=xml有一个我试图解析和显示的xml的例子。

So any idea/ tips on how i would go around just parsing this one entry and displaying it to the textbox. 所以任何关于如何解析这一条目并将其显示到文本框的想法/提示。 the only thing i am after is the lyrics data and the URL as that's all i will be displaying on the page. 我唯一能追求的是歌词数据和URL,就像我将在页面上显示的一样。

You can use linq-to-xml to query specific information from xml. 您可以使用linq-to-xml从xml查询特定信息。 Following is an example to get lyrics and url using linq-to-xml : 以下是使用linq-to-xml获取歌词和网址的示例:

var doc = XDocument.Parse(xml);
var lyrics = doc.Root.Element("lyrics").Value;
var url = doc.Root.Element("url").Value;

With that, lyrics and url information extracted and ready to be displayed in textbox or any other control of choice. 有了它,提取的歌词和网址信息就可以在文本框或任何其他选择控件中显示。 Note: xml is xml string downloaded from link in the question. 注意: xml是从问题中的链接下载的xml字符串。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM