首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XML解析+ windows phone 7

XML解析+ windows phone 7
EN

Stack Overflow用户
提问于 2010-12-12 15:49:46
回答 2查看 5.6K关注 0票数 2

我需要有关在windows phone7中解析XML数据的帮助。我看起来类似于示例XMl parsign example,但在为xml数据编写LINQ查询时遇到了问题。

代码语言:javascript
复制
<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文档提供的任何帮助。

感谢并问候苏莉娅

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-12-13 00:52:14

正如Jon上面所说的,你的问题需要更多的解释,但也许下面的内容就是你想要的:

代码语言:javascript
复制
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()
         };
票数 2
EN

Stack Overflow用户

发布于 2010-12-13 04:44:36

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

代码语言:javascript
复制
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;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4420749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档