110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
class Program
{
static void Main()
{
XDocument xDocFileA = XDocument.Load(@"d:\file1.xml");
XDocument xDocFileB = XDocument.Load(@"d:\file2.xml");
XElement xeAdd= xDocFileA.Element("datamodel").Elements()
.FirstOrDefault(x=>x.Attribute("id").Value =="1") ;
XElement xe = xDocFileB.Element("datamodel");
xe.Add(xeAdd);
xDocFileB.Save(@"d:\file2.xml");
}
}
XMLDocument x1= XMLDocument();
xl.Load("file1.xml");
XMLDocument x2= XMLDocument();
x2.Load("file2.xml");
XMLNode node = x1.SelectSingleNode("/datamodel/DataID[@id='1']");
XMLNode node2 = node.Clone();
X2.SelectSingleNode("//datamodel").ApplendChild(node2);