I have several xml file with different elements in it. I have generated a xsd file for each xml file through visual studio and also generated ac# file by typing xsd fileName.xsd Now i'm trying to get all elements of these various xml file and put it in a single xml file. Any idea how to do it? When i try to serialize each xml file separately i'm not able to fetch the elements value.
You can use this short snippet bellow to merge two XDocuments,
string oldXmlFile = @"Path";
string newXmlfile = @"Path2";
XDocument document = XDocument.Load(oldXmlFile);
document.Root.Add(XDocument.Load(newXmlfile).Root.Elements());
document.Save(oldXmlFile);
but then duplicate elements will also populate the merged document, so here comes a handy little method that also checks for duplicate items.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.