将相同的命名为xml节点

时间:2016-06-08 13:53:40

标签: c# xml

我编辑了这个小MSDN示例https://support.microsoft.com/en-us/kb/311530

我有以下2个XML&#39>

Book1.xml

<?xml version="1.0"?>
<catalog>
<book1 id="1" />
<bookSum number="1" />
</catalog>

列出book2.xml

<?xml version="1.0"?>
<catalog>
<book2 id="2" />
<bookSum number="1" specialAttribute="123" />
</catalog>

C#代码

XmlReader xmlreader1 = XmlReader.Create(@"C:\Book1.xml");
XmlReader xmlreader2 = XmlReader.Create(@"C:\book2.xml");

DataSet ds = new DataSet();
ds.ReadXml(xmlreader1);
DataSet ds2 = new DataSet();
ds2.ReadXml(xmlreader2);
ds.Merge(ds2);
ds.WriteXml(@"C:\Merge.xml");
Console.WriteLine("Completed merging XML documents");

Merge.xml (Book1.xml + Book2.xml)

<?xml version="1.0" standalone="yes"?>
<catalog>
  <book1 id="1" />
  <bookSum number="1" />
  <bookSum number="1" specialAttribute="x" />
  <book2 id="2" />
</catalog>

问题是

如何加入

<bookSum number="1" />
<bookSum number="1" specialAttribute="123" />

分成一行?

<bookSum number="2" specialAttribute="123" />

1 个答案:

答案 0 :(得分:0)

我这样做并正在工作:

redirect_uri