In wp7 i want to parse xml tag
.Xml :
<top>
<value name="Group A">
<team position="1" name="india" won="10" lose="5"/>
<team position="2" name="pakistan" won="5" lose="5"/>
</value>
<value name="Group 开发者_Python百科B">
<team position="1" name="Aus" won="10" lose="5"/>
<team position="2" name="newzeland" won="5" lose="5"/>
</value>
</top>
i want output like this,
Group A
1 India 10 5
2 pak 5 10
Group B
1 Aus 5 5
2 Neszeland 5 5
I' m using parser like this,
list = (from story in xmlTweets.Descendants("value")
select new ViewModel
{
group= story.Attribute("name").Value,
}).ToList();
list1 = (from story in xmlTweets.Descendants("team")
select new ViewModel
{
position= story.Attribute("position").Value,
name= story.Attribute("name").Value,
won= story.Attribute("won").Value,
lose= story.Attribute("lose").Value,
}).ToList();
output:
Group A
Group B
1 India 10 5
2 pak 5 10
1 Aus 5 5
2 Neszeland 5 5
Please tell me some idea to do this.
thanks.
Currently you've got two separate lists - one for groups and one for teams. It looks to me like your view model needs to be richer - something like:
list = xml.Descendants("value")
.Select(group => new GroupViewModel
{
Group = (string) group.Attribute("name"),
Results = group.Elements("team")
.Select(team => new TeamViewModel
{
Position = (int) team.Attribute("position"),
Name = (string) team.Attribute("name"),
Won = (int) team.Attribute("won"),
Lost = (int) team.Attribute("lose")
})
.ToList()
})
.ToList();
精彩评论