2010-12-12 95 views
2

我需要关于windows phone的XML数据的解析7.我期待类似XMl parsign example 但我写的XML数据的LINQ查询时像XML解析+ Windows Phone 7的

<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文档

感谢和问候 苏里亚

+0

你已经展示了你想要解析的XML,但不是你遇到什么问题,XML来自哪里,或者到目前为止你尝试过的。这使你很难帮助你。 – 2010-12-12 07:55:18

回答

2

正如上面乔恩说,任何帮助非常感激,你的问题需要更多的前plaination,但可能像下面就是你想找的:

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() 
     }; 
+0

谢谢你!!这正是我想要完成的。 – surya 2010-12-16 02:41:41

+0

什么是停止?它是字符串还是列表? – Jeeva 2011-10-07 06:44:24

+0

停止是一个节点的列表。 – 2011-10-10 14:12:33

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; 
+0

非常感谢回复..这会帮助我:-) – surya 2010-12-16 02:42:08