C# 在其他Xml节点中复制Xml节点
我有一个xml文件C# 在其他Xml节点中复制Xml节点,c#,xml,xml-parsing,C#,Xml,Xml Parsing,我有一个xml文件 <students> <student> <identity> <key>101</key> </identity> <information> <name>abc</name> <age>12</age>
<students>
<student>
<identity>
<key>101</key>
</identity>
<information>
<name>abc</name>
<age>12</age>
<address>xyz</address>
.....
</information>
<otherinformation>
<project>
<name>project1</name>
<duration>three months</duration>
</project>
.......
</otherinformation>
</student>
<student>
<identity>
<key>102</key>
</identity>
<information>
<name>def</name>
<age>12</age>
<address>uvw</address>
.....
</information>
<otherinformation>
<project>
<name>project2</name>
<duration>one month</duration>
</project>
</otherinformation>
</student>
</students>
101
abc
12
xyz
.....
项目1
三个月
.......
102
def
12
紫外线
.....
项目2
一个月
因此,给定键101的值,我想将信息节点和otherinformation
复制到所有学生手中的任何键。因此,在本例中,具有键102的学生在复制后将具有与键101相同的信息和其他信息
节点
我怎样才能做到这一点呢?试试这个
XDocument d = XDocument.Parse(xml);
var students = d.Descendants("student").ToList();
var student101 = students.First(i => i.Element("identity").Element("key").Value == "101");
foreach (var student in students)
{
student.Descendants("information").Single().ReplaceWith(student101.Descendants("information").Single());
}
var x = d.ToString();
您正在寻找XLINQ。我们可以用XLINQ来完成吗?由于xml文件很大,大约有30000行,所以我正在寻找多种解决方案。