【问题标题】:xml parsing webapi to listview windows store apps c#xml将webapi解析为listview windows store应用程序c#
【发布时间】:2014-09-13 17:41:31
【问题描述】:

我是 xml 解析的新手,我已将 webapi xmlparsing 与 Windows 商店应用程序一起使用。 我来自网络的 xml 是:

 <product>
  <id_products>1</id_products>   
   <images>
    <src isrenderimg="0" imagecodename="202">http://abcd.com/imagecache/abcjpg</src> 
   </images>
 </product>
 <product>
   <id_products>2</id_products> 
    <images>
      <src isrenderimg="0"imagecodename="203">http://abcd.com/imagecache/abc1.jpg</src> 
      <src isrenderimg="0" imagecodename="204">http://abcd.com/imagecache/abc2.jpg</src> 
    </images>
  </product>

我有 在主页上使用此代码解析此 xml:

public class demo
  {
     public string Image { get; set; }
  }

 protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var xDoc = XDocument.Load(apiurl of xml);
        var data = from query in xDoc.Descendants("images")
          select new demo
            {
              Image = query.Element("src").Value,
            };
        this.ListView1.DataContext = data;
    }`

我的问题是 xml 在图像标签中包含多个 src 标签,如上面的 xml 代码所示。 所以我的列表视图只显示第一个 src 标记的图像而不是其他的我想显示 src 标记的所有图像,这些图像在我的列表视图中的图像标记中怎么可能?请帮助我。提前致谢。

【问题讨论】:

  • 请任何人给我解决方案

标签: c# listview xml-parsing windows-store-apps asp.net-web-api


【解决方案1】:

假设您想简单地显示来自&lt;images&gt; 中每个&lt;src&gt; 标记的所有图像,您可以尝试这种方式:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var xDoc = XDocument.Load(apiurl of xml);
    var data = from query in xDoc.Descendants("images").Elements("src")
               select new demo
               {
                  Image = query.Value,
               };
    this.ListView1.DataContext = data;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多