jonson1126
各种问题 各种方法 各种解决 路要自己走一遍才知个中滋味

http://support.microsoft.com/kb/311530/zh-cn

Books1.xml

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
   </book>
   <book id="bk102">
      <author>Jeanette, Dasha</author>
      <title>Quack the Duck</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
   </book>
</catalog>
        

Books2.xml

<?xml version="1.0"?>
<catalog>
<book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
   </book>
   <book id="bk107">
      <author>Vinzovskaia, Irina</author>
      <title>Piano Fort A</title>
      <genre>Romance</genre>
      <price>4.95</price>
   </book>
</catalog>

C#.NET

using System;
using System.Xml;
using System.IO;
using System.Data ;
            
try
    {
        XmlTextReader xmlreader1 = new XmlTextReader("C:\\Books1.xml");
        XmlTextReader xmlreader2 = new XmlTextReader("C:\\Books2.xml");

        DataSet ds = new DataSet();
        ds.ReadXml(xmlreader1);
        DataSet ds2 = new DataSet();
        ds2.ReadXml(xmlreader2);
        ds.Merge(ds2);
        ds.WriteXml("C:\\Books.xml");
        Console.WriteLine("Completed merging XML documents");
    }
    catch (System.Exception ex)
    {
        Console.Write(ex.Message);
    }
Console.Read();  

 

posted on 2014-01-20 19:52  jonson1126  阅读(179)  评论(0编辑  收藏  举报