XML Parsing + windows phone 7
I need help regarding parsing of XML data in windows phone 7. I am looking something similar to the example XMl parsign example But i am facing issue when开发者_如何学运维 writing the LINQ query for xml data like
<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>";
I would be really grateful for any help provided for parsing multilevel xml doc
Thanks and Regards Surya
As Jon says above, your question needs a bit more explaination, but maybe something like the following is what your looking for:
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()
};
Without knowing exactly what you're trying to do it's hard to provide exactly what you want but the following shows a way (there are many more) of accessing all the nodes in the example 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;
精彩评论