Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging XML files

Status
Not open for further replies.

pbb72

Programmer
Mar 27, 2004
38
0
0
NO
I need to merge a huge amount of XML files into one. The files all have the following structure:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top