WP7 如何解析 XML? [英] WP7 How to parse the XML?
本文介绍了WP7 如何解析 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 wp7 中我想解析 xml 标签
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 B">
<team position="1" name="Aus" won="10" lose="5"/>
<team position="2" name="newzeland" won="5" lose="5"/>
</value>
</top>
我想要这样的输出,
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();
输出:
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.
谢谢.
推荐答案
目前您有两个单独的列表 - 一个用于小组,一个用于团队.在我看来,您的视图模型需要更丰富 - 类似于:
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();
这篇关于WP7 如何解析 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文