Merge 2 XML (Dotnet Factory)

Share this post
FaceBook  Twitter  Mixx.mn     

To merge two XML files, use following code:-

1) Using DotNetFactory create an Instance for both XML files

2) Set XML DataSet variable

3) Read both XMLs

4) Merge XML

5) Save Final XML to a location

6) Close XML

7) Discard all variables.

 

Dim objReader1,objReader2,xmldata1,xmldata2


'1) Using DotNetFactory create an Instance for both XML files
Set objReader1 = DotNetFactory.CreateInstance("System.Xml.XmlTextReader", "System.Xml","C:\...\1.xml") ' 'Create instance of1st XML
Set objReader2 = DotNetFactory.CreateInstance("System.Xml.XmlTextReader", "System.Xml","C:\...\2.xml") ' 'Create instance of 2nd XML

'2) Set XML DataSet variable
Set xmldata1 = DotNetFactory.CreateInstance("System.Data.DataSet", "System.Data")
Set xmldata2 = DotNetFactory.CreateInstance("System.Data.DataSet", "System.Data")

'3) Read both XMLs
xmldata1.ReadXml(objReader1)
xmldata2.ReadXml(objReader2)

'4) Merge XML
xmldata1.Merge(xmldata2)

'5) Save Final XML to a location
xmldata1.WriteXml("C:\...\3.xml")

'6) Close XML
objReader1.close
objReader2.close

'7) Discard all variables.
Set objReader1=Nothing
Set objReader2=Nothing

Set xmldata1=nothing
Set xmldata2=nothing