Linq to Xml 按标签分组
我有一个与此类似的 xml:
<data>
<date>24/11</date>
<info>Info I want to get</info>
<info>Info I want to get</info>
<info>Info I want to get</info>
<date>25/11</date>
<info>Info I want to get</info>
<info>Info I want to get</info>
<info>Info I want to get</info>
</data>
问题是,我能够获取所有信息标签,但我获取所有日期的结果。
我不知道日期是什么,因为它们是动态生成的。我所知道的是,我可能有一个带有一两个日期标签的数据标签
我希望我可以在列表框中显示第一个日期的信息,在另一个列表框中显示第二个日期的信息。我怎样才能做到这一点?
期望的输出:
textbox with the first date
value of tag info related to the first date
value of tag info related to the first date
value of tag info related to the first date
如果有第二个日期,则也打印它:
textbox with the second date
value of tag info related to the second date
value of tag info related to the second date
value of tag info related to the second date
谢谢!
I have a xml similar to this one:
<data>
<date>24/11</date>
<info>Info I want to get</info>
<info>Info I want to get</info>
<info>Info I want to get</info>
<date>25/11</date>
<info>Info I want to get</info>
<info>Info I want to get</info>
<info>Info I want to get</info>
</data>
The thing is, Im able to get all the info tags, but I get the results from all dates.
I dont know what the dates will be, since the are dynamic generated. What I know is that I may have a data tag with one or two date tags
I wish I could show the first date´s info on a list box and the second date´s info on another listbox. How can I do that?
Desirable Output:
textbox with the first date
value of tag info related to the first date
value of tag info related to the first date
value of tag info related to the first date
If there´s a second date then print it too:
textbox with the second date
value of tag info related to the second date
value of tag info related to the second date
value of tag info related to the second date
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您想要填充哪种类型的列表框(例如 Windows 窗体、ASP.NET、WPF),因此我只是向您展示如何对 XML 输入进行分组:
然后输出是例如
I don't know what kind of ListBox (e.g. Windows Forms, ASP.NET, WPF) you want to populate so I simply show you how to group that XML input:
Output then is e.g.