1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public void Merge_Files()
{
try
{
XDocument doc = XDocument.Load(listView2.Items[0].Text);
var headerDoc = doc.Root.Element("CallAccountingList");
var corpsDoc = doc.Root.Elements("CallAccounting");
for (int i = 1; i < listView2.Items.Count; ++i);
{
string path = listView2.Items[i].Text;
XDocument doc1 = XDocument.Load(path);
var corpsDoc1 = doc1.Root.Elements("CallAccounting");
corpsDoc = corpsDoc.Concat(corpsDoc1);
}
// Création du fichier XDocument de sortie
XNamespace aw = "http://www.w3.org/2001/XMLSchema-instance";
doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(aw + "CallAccountingList",
headerDoc,
corpsDoc));
// Transformer le XDocument en XmlDocument
result.LoadXml(doc.ToString());
result.Save("Merged_File.xml");
label4.Text = "Fusion done";
}
catch (System.Exception ex)
{
listView1.Items.Add("Erreur de fusion : " + ex);
Console.WriteLine(ex);
}
} |