【问题标题】:RSS on the Windows Phone 7Windows Phone 7 上的 RSS
【发布时间】:2012-04-11 12:02:34
【问题描述】:

我是Windows phone 7的开发者,我想问一下:如果我去.xml代码,有没有这样的

<?xml version="1.0" encoding="utf-8"?>

<artists>
<images>
<image size="1">http://userserve-ak.last.fm/serve/34/17666215.jpg</image>
<image size="2">http://userserve-ak.last.fm/serve/64/17666215.jpg</image>
</images>
</artists>

那么我该如何选择那里的第二个元素呢?

【问题讨论】:

    标签: xml windows-phone-7 rss


    【解决方案1】:

    我了解到您想要解析此 XML 文件并获取第二个元素值,因此您可以使用以下方法来执行此操作:

    XDocument xmlDocument = XDocument.Parse("path_to_xml_file");
    //you can also pass a the content as a string or a stream reader
    
    XElement image = (from element in xmlDocument.Element("artists").Element("images").Descendants("image")
                              where element.Attribute("size").Value == "2"
                              select element).FirstOrDefault();
    
    System.Diagnostics.Debug.WriteLine(image.Value);
    

    然后添加这个导入:

    using System.Linq;
    using System.Xml.Linq;
    

    并将对 System.Xml.Linq.dll 的引用添加到您的项目中。

    我认为这个链接对你也有帮助:How to Get XML Node from XDocument

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多