2010-12-12 81 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