rt

解决方案 »

  1.   

    读取:DataSet.ReadXml(filepath, XmlReadMode.Auto);
    写入:System.IO.FileStream myFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);
                        System.Xml.XmlTextWriter myWriter = new System.Xml.XmlTextWriter(myFileStream, Encoding.Unicode);
                        thisDataset.WriteXml(myWriter);
                        myWriter.Close();
      

  2.   

      //读写这里面都有了,自己改改吧
    public  void SaveSet(string singlePackage, string Form, string Button,ArrayList arrarSel)
            {
                string strPath = Application.StartupPath + "\\ReportSet.xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(strPath);            XmlNodeList nodeList = xmlDoc.SelectSingleNode("ReportSet").ChildNodes;
                foreach (XmlNode xn in nodeList)//遍历所有子节点 
                {                XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 
                    if (xe.GetAttribute("ID") == singlePackage && xe.GetAttribute("Form") == Form && xe.GetAttribute("Button") == Button)
                    {
                        xmlDoc.SelectSingleNode("ReportSet").RemoveChild(xe);
                        break;                }
                }
                XmlNode root = xmlDoc.SelectSingleNode("ReportSet");//查找DevChokMods
                XmlElement xe1 = xmlDoc.CreateElement("singlePackage");//创建一个DevChokMod节点
                xe1.SetAttribute("ID", singlePackage);
                xe1.SetAttribute("Form", Form);//设置该节点InfoType属性
                xe1.SetAttribute("Button", Button);
                
                for (int i = 0; i < arrarSel.Count ; i++)
                {               
                        XmlElement xesub1 = xmlDoc.CreateElement("rptID");
                        xesub1.InnerText =arrarSel [i].ToString ();//设置文本节点
                        xe1.AppendChild(xesub1);//              
                }            root.AppendChild(xe1);            xmlDoc.Save(strPath);        }
      

  3.   

    File.Copy就完了,干嘛来回的读写
      

  4.   

    刚看了另外的帖子你把你的样例贴出来
    原来的和生成后的不用循环节点
    直接操作需要复制内容的节点的OuterXml和复制后的节点的InnerXml就可以了举个例子原来的XML<?xml version="1.0" encoding="gb2312"?>
    <Root>
      <A>A</A>
      <B>B</B>
    </Root>
    复制到的XML<?xml version="1.0" encoding="gb2312"?>
    <Root>
      <TempA></TempA>
    </Root>
    代码如下XmlDocument doc1 = new XmlDocument();
    doc1.Load(你的需要复制的XML);
    XmlDocument doc2 = new XmlDocument();
    doc2.Load(最后得到的XML);
    XmlNode root1 = doc1.DocumentElement;
    XmlNode temp = doc2.SelectSingleNode("/Root/TempA");
    temp.InnerXml = root.OurerXml;
    doc2.Save(filePath);
    最后的结果<?xml version="1.0" encoding="gb2312"?>
    <Root>
      <TempA>
        <Root>
          <A>A</A>
          <B>B</B>
        </Root>
      </TempA>
    </Root>