【发布时间】:2011-03-01 16:44:58
【问题描述】:
我是 LINQ 和 C# 的新手,但我有一个从数据库表生成的 xml 文件。 XML 文档中有一个名为“group”的元素,我想用名为“groups”的元素包装所有 group 元素。
XML 文档的摘录是:
<members>
- <user>
<fullname>John Smith</fullname>
<username>SmithA</username>
<email>John.smith@test.com/email>
<distinguishedName>xxx</distinguishedName>
<group>London</group>
</user>
- <user>
<fullname>Sue Jones</fullname>
<username>JonesS</username>
<email>Sue.Jones@test.com/email>
<distinguishedName>xxx</distinguishedName>
<group>London</group>
</user>
</members>
我在 C# ASP.NET 中努力编写代码的最终结果是:
<members>
- <user>
<fullname>John Smith</fullname>
<username>SmithA</username>
<email>John.smith@test.com/email>
<distinguishedName>xxx</distinguishedName>
<groups>
<group>London</group>
<groups>
</user>
- <user>
<fullname>Sue Jones</fullname>
<username>JonesS</username>
<email>Sue.Jones@test.com/email>
<distinguishedName>xxx</distinguishedName>
<groups>
<group>London</group>
<groups>
</user>
</members>
我们将不胜感激。
【问题讨论】: