Thursday, July 30, 2009

By using c#.net how to combine two xml files into one xml file.Give me sample code for that.?

XML files are just text files. Why can't you just read one in as a text file, open the other for append, and write out what you just read in?

By using c#.net how to combine two xml files into one xml file.Give me sample code for that.?
the logic for this


Read the first file by loading it in an Xml document.


load another file in another xml document and take its outerxml and append it into the first one and then save the first document.





XmlDocument xmlfile1=null;


XmlDocument xmlfile2=null;











try


{





xmlfile1 =new XmlDocuiment();


xmlfile1.Load("%26lt;PATH OF XML FILE1 %26gt;");





xmlfile2 =new XmlDocuiment();


xmlfile2.Load("%26lt;PATH OF XML FILE2 %26gt;");





xmlfile1.DocumentElement.InnerXml+=xml...





xmlfile1.Save(("%26lt;PATH OF XML FILE1 %26gt;");


}


catch(Exception e)


{


throw e;


}


finally


{


if (xmlfile1!=null) xmlfile1=null;


if (xmlfile2!=null) xmlfile2=null;


}





so simple that's it .
Reply:Please look at the link below for code and explanation.





http://msdn.microsoft.com/msdnmag/issues...





hope that helps.





Cheers


No comments:

Post a Comment