There is no one single recipe, it depends on the schema of each file. In some cases, XML can contradict to each other, so such problem may be solvable or not. One simple example is: merging can make unique attribute values (required by the schema of the target file, such as
id
) non-unique.
There can be different methods of doing it. A trivial approach is parsing all files and then combining them into a DOM document, checking validity, etc. Another method could be forward-only, when you open input files with
XmlReader
, all at once or one-by-one and using the class
XmlWriter
for the target file.
Technically, you can refer to my short overview of different XML classes available on .NET FCL:
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
and System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
Good luck,
—SA