tags:

views:

90

answers:

2

I am having problem to merge 2 or more xml files into 1 using c#.

I am doing it with DataSets:

//ds1,ds2,ds3 are DataSets
private void MyMethod()
{
    ds1.ReadXml(tmpStream);
    ds2.ReadXml(tmpStream);    
    ds1.Merge(ds2);
}

but i dont want to use DataSet. i am searching for another way.

first XML is

<?xml version="1.0" encoding="utf-8"?>
<catalog>
  <item>
    <path>'filePath'</path>
    <deleted>0</deleted>
    <date>9/23/2010 11:30:03 AM</date>
  </item> 
</catalog>

the second is

<?xml version="1.0" encoding="utf-8"?>
<catalog>
  <item>
    <path>'filePath'</path>
    <deleted>0</deleted>
    <date>9/23/2010 11:30:03 AM</date>
  </item> 
</catalog>

result must be

<?xml version="1.0" encoding="utf-8"?>
    <catalog>
      <item>
        <path>'filePath'</path>
        <deleted>0</deleted>
        <date>9/23/2010 11:30:03 AM</date>
      </item> 
      <item>
        <path>'filePath'</path>
        <deleted>0</deleted>
        <date>9/23/2010 11:30:03 AM</date>
      </item> 
    </catalog>
A: 

check this link

http://stackoverflow.com/questions/1627623/c-merge-xml-files-but-retain-everything-from-the-two-files-including-version-nu

Bala
it create new file but i want merge it and use it. Not save in file
AEMLoviji
+3  A: 

Though this isn't really clear of what sort of merge you want, this article Merging XML Files, Schema Validation, and More might help you get the idea.

Easiest could be, if you dont want any checks to be performed(duplicates, zombies, etc)

var ResultXml = XDocument.Load("file1.xml");
ResultXml.Root.Add(XDocument.Load("file2.xml").Root.Elements());
KMan