zoukankan      html  css  js  c++  java
  • 0120如何合并两个使用 System.Xml 使用 Visual C#.NET 的 XML 文档中的数据

    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();  
  • 相关阅读:
    centos7 安装 tesseract4.1
    08 图的数据结构和算法
    07 树形结构及其算法
    05 数组与链表算法
    06 堆栈与队列算法
    04 查找与哈希算法
    03 排序算法
    javascript 标签轮播
    tomcat URI get 参数中文传到后台 乱码 URIEncoding
    javascript 标签切换
  • 原文地址:https://www.cnblogs.com/jonson1126/p/3527434.html
Copyright © 2011-2022 走看看