我需要有关在windows phone7中解析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文档提供的任何帮助。
感谢并问候苏莉娅
发布于 2010-12-13 00:52:14
正如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()
};发布于 2010-12-13 04:44:36
在不确切知道要做什么的情况下,很难确切地提供您想要的内容,但是下面展示了一种访问示例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;https://stackoverflow.com/questions/4420749
复制相似问题