【问题标题】:XML Parsing + windows phone 7XML 解析 + windows phone 7
【发布时间】:2010-12-13 04:44:35
【问题描述】:

我需要有关在 windows phone 7 中解析 XML 数据的帮助。我正在寻找类似于示例 XMl parsign example 的内容 但是我在为 xml 数据编写 LINQ 查询时遇到了问题,例如

<toursList> 
<tour>
<title>short tour </title>
 <description>the short tour is kinda quick! </description>
 <stop> <title>tabaret hall</title>
 <description>tabaret hall </description>
  <location>
    <latitude>45.424585</latitude>
      <longitude>-75.68608</longitude>
   </location>
</stop>
</tour>
</toursList>";

非常感谢为解析多级 xml 文档提供的任何帮助

感谢和问候 苏里亚

【问题讨论】:

  • 您已经展示了您尝试解析的 XML,但没有展示您遇到的问题、XML 的来源或到目前为止您尝试过的内容。这让您很难为您提供帮助。

标签: xml windows-phone-7


【解决方案1】:

正如 Jon 上面所说,您的问题需要更多解释,但也许您正在寻找类似以下内容:

var tours = from tour in toursListElement.Elements("tour")
         select new Tour
         {
              Description = tour.Element("description"),
              Stops = (from stop in tour.Elements("stop")
                      select new Stop
                      {
                           Title = stop.Element("title"),
                           Description = stop.Element("description"),
                           Location = new Location
                                      {
                                           Latitude = stop.Element("location").Element("latitude"),
                                           Longitude = stop.Element("location").Element("longitude")
                                      }
                      }).ToList()
         };

【讨论】:

  • 什么是止损?是字符串还是列表?
  • Stops 是 节点的列表。
【解决方案2】:

在不确切知道您要做什么的情况下,很难准确地提供您想要的东西,但以下显示了一种访问示例 XML 中所有节点的方法(还有更多)。

var tours = from list in xdoc.Elements("toursList")
            select list.Elements("tour");

var tour = tours.First();

var title = tour.Elements("title").First().Value;

var desc = tour.Elements("description").First().Value;

var stop = tour.Elements("stop").First().Value;

var stopTitle = stop.Elements("title").First().Value;

var stopDescription = stop.Elements("description").First().Value;

var stopLocation = stop.Elements("location").First().Value;

var stopLat = stopLocation.Elements("latitude").First().Value;

var stopLong = stopLocation.Elements("longitude").First().Value;

【讨论】:

  • 非常感谢您的回复。这对我有帮助:-)
猜你喜欢
  • 1970-01-01
  • 2012-01-22
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 2011-10-19
  • 2013-01-11
  • 1970-01-01
  • 2013-01-16
相关资源
最近更新 更多