用C#如何将两个XML合并为一个XML?
现在有连个XML,如下:
1:
<?xml version= "1.0 " encoding= "gb2312 " ?>
<ESEWorkspace xmlns= "http://www.esesoft.com/ese ">
<DataSources>
<Datasource>
<DSType> 0 </DSType>
<DSServer/>
<Instance/>
<Database/>
<User/>
<Password/>
<DSAlias/>
</Datasource>
</DataSources>
</ESEWorkspace>
2:
<?xml version= "1.0 " encoding= "gb2312 " ?>
<ESEWorkspace xmlns= "http://www.esesoft.com/ese ">
<RS> 1 </RS>
</ESEWorkspace>
如何用C#将他们合并为一个XML:
<?xml version= "1.0 " encoding= "gb2312 " ?>
<ESEWorkspace xmlns= "http://www.esesoft.com/ese ">
<DataSources>
<Datasource>
<DSType> 0 </DSType>
<DSServer/>
<Instance/>
<Database/>
<User/>
<Password/>
<DSAlias/>
</Datasource>
</DataSources>
<RS> 1 </RS>
</ESEWorkspace>
谢谢
------解决方案-------------------- <%@ Page Language= "C# " %>
<%@ Import Namespace= "System.Xml " %>
<script runat= "server ">
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc1 = new XmlDocument();
doc1.Load(Server.MapPath( "1.xml "));
XmlDocument doc2 = new XmlDocument();
doc2.Load(Server.MapPath( "2.xml "));
XmlNode root1 = doc1.DocumentElement;
XmlNode root2 = doc1.ImportNode(doc2.DocumentElement.FirstChild, true);
root1.AppendChild(root2);
doc1.Save(Server.MapPath( "3.xml "));
}
</script>