在 LINQ select 语句中使用 xml 父数据
假设我已经有了这个 XML:
<items>
<item name="thumb">
<downloadStream>test1</downloadStream>
<downloadStream>test2</downloadStream>
<downloadStream>test3</downloadStream>
</item>
<item name="photo">
<downloadStream>test5</downloadStream>
<downloadStream>test6</downloadStream>
<downloadStream>test7</downloadStream>
</item>
</items>
我正在尝试编写一个 LINQ 语句,它将把它转换为以下字符串:
{ "thumb test1",
"thumb test2",
"thumb test3",
"photo test5",
"photo test6",
"photo test7", }
换句话说,它将父节点的属性附加到每个子节点的内部字符串。
他们是我可以使用一个 LINQ 查询来做这样的事情的一种方式吗?我可以找到几种方法将其分解为多个步骤,但我有一种感觉,这是一种更简单的方法。
谢谢!
lets say that I've got this XML:
<items>
<item name="thumb">
<downloadStream>test1</downloadStream>
<downloadStream>test2</downloadStream>
<downloadStream>test3</downloadStream>
</item>
<item name="photo">
<downloadStream>test5</downloadStream>
<downloadStream>test6</downloadStream>
<downloadStream>test7</downloadStream>
</item>
</items>
I'm trying to write a LINQ statement which will convert this to the following strings:
{ "thumb test1",
"thumb test2",
"thumb test3",
"photo test5",
"photo test6",
"photo test7", }
In other words, it appends the attribute from the parent node to the inner-string of each child node.
Is their a way that I can use one LINQ query to do something like this? I can find a few ways to break it up into multiple steps, but I have a feeling that their is an easier way.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 VB.NET 中的。同样的事情在 C# 中也是可能的,但我更熟悉 VB 语法。
Here it is in VB.NET. Same thing would be possible in C#, but I'm more familiar with the VB syntax.