Created
May 14, 2014 01:17
-
-
Save pisceanfoot/15aa9b6e081a89c7a63a to your computer and use it in GitHub Desktop.
merge multi xml file to xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// | |
/// </summary> | |
public static class XmlUtils | |
{ | |
/// <summary> | |
/// MergeFiles to a single file | |
/// </summary> | |
/// <param name="files"></param> | |
/// <param name="fileContentMergeFail"></param> | |
/// <returns></returns> | |
public static string MergeFiles(List<string> files) | |
{ | |
XmlDocument doc = new XmlDocument(); | |
if (files.Count > 0) | |
{ | |
string fileToMerge = null; | |
for (int i = 0; i < files.Count; i++) | |
{ | |
fileToMerge = files[i]; | |
if (!File.Exists(fileToMerge)) | |
{ | |
throw new FileNotFoundException(fileToMerge); | |
} | |
if (doc.DocumentElement == null) | |
{ | |
doc.Load(fileToMerge); | |
} | |
else | |
{ | |
XmlDocument docTemp = new XmlDocument(); | |
docTemp.Load(fileToMerge); | |
foreach (XmlNode node in docTemp.DocumentElement.ChildNodes) | |
{ | |
XmlNode nodeTemp = doc.ImportNode(node, true); | |
doc.DocumentElement.AppendChild(nodeTemp); | |
} | |
} | |
} | |
} | |
return doc.OuterXml; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment