I need to merge a huge amount of XML files into one. The files all have the following structure:
I've written the following code to do this:
I have two problems with my code:
1. Memory usage: on a small testrun, the application used 500MB memory for a merged XML file of 80MB. Do I have a big memory leak, or is this to be expected for such huge amounts of XML data?
2. The resulting file misses the <!DOCTYPE> and has an added level above <FILE> called <NewDataSet>. How do I add the <!DOCTYPE> and remove the <NewDataSet> from the resulting XML?
Thanks, Peter
Code:
<!DOCTYPE ...>
<FILE>
<REC ...>
<FLD ...>...</FLD>
...
</REC>
...
</FILE>
I've written the following code to do this:
Code:
private void btnOpen_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
progressBar1.Maximum = openFileDialog1.FileNames.Length;
XmlReaderSettings xmlsetting = new XmlReaderSettings();
xmlsetting.ProhibitDtd = false;
DataSet ds = new DataSet();
DataSet dsDest = new DataSet();
XmlReader xmlread;
foreach (string s in openFileDialog1.FileNames)
{
xmlread = XmlReader.Create(s, xmlsetting);
ds.Clear();
ds.ReadXml(xmlread);
dsDest.Merge(ds);
xmlread.Close();
progressBar1.Value++;
}
if (saveFileDialog1.ShowDialog() != DialogResult.OK) return;
dsDest.WriteXml(saveFileDialog1.FileName);
}
I have two problems with my code:
1. Memory usage: on a small testrun, the application used 500MB memory for a merged XML file of 80MB. Do I have a big memory leak, or is this to be expected for such huge amounts of XML data?
2. The resulting file misses the <!DOCTYPE> and has an added level above <FILE> called <NewDataSet>. How do I add the <!DOCTYPE> and remove the <NewDataSet> from the resulting XML?
Thanks, Peter