【发布时间】:2013-09-10 10:43:56
【问题描述】:
说,这是我的 XML 文件
XML 文件 1
<Root>
<Parent>
<Child>1</Child>
<child>2</Child>
</Parent>
<Parent>
<child>3</Child>
<Child>4</Child>
</Parent>
</Root>
Xml 文件 2
<Root>
<Parent>
<Child>5</Child>
<Child>6</Child>
</Parent>
<Parent>
<Child>7</Child>
<Child>8</Child>
</Parent>
</Root>
生成的 XML 文件(根据我的要求)
<Root>
<Parent>
<Child>1</Child>
<Child>2</Child>
</Parent>
<Parent>
<Child>3</Child>
<Child>4</Child>
</Parent>
<Parent>
<Child>5</Child>
<Child>6</Child>
</Parent>
<Parent>
<Child>7</Child>
<Child>8</Child>
</Parent>
</Root>
在下面的函数中,我提供了 xml 文件的路径以组合在一个字符串数组中并尝试合并它们
private void BindDataInGrid(string[] argFilePaths)
{
XDocument tempFile = XDocument.Load(argFilePaths[0]);
for (int i = 1; i < argFilePaths.Length; i++)
{
tempFile.Descendants("Parent")
.Union(XDocument.Load(argFilePaths[i]).Root.Descendants("Parent"));
}
}
在 tempFile 中,只有第一个文件的记录,其他文件没有。
【问题讨论】:
-
操作结束时需要保存
tempFile。