XmlTextReader myReader = new XmlTextReader("abc.xml");
XmlDocument mySourceDoc = new XmlDocument();
mySourceDoc.Load(myReader);
myReader.Close();
myReader = new XmlTextReader("pqr.xml");
XmlDocument myDestDoc = new XmlDocument();
myDestDoc.Load(myReader);
myReader.Close();
XmlNode rootDest = myDestDoc["root node"];
XmlElement nodeOrig = (XmlElement)mySourceDoc["root node"].ChildNodes[0];
XmlNode nodeDest = myDestDoc.ImportNode(nodeOrig, true);
try
{
rootDest.AppendChild(nodeDest);
}
catch (Exception ex)
{
MessageBox.Show("" + ex);
}
XmlTextWriter myWriter = new XmlTextWriter("pqr.xml", Encoding.UTF8);
myWriter.Formatting = Formatting.Indented;
myDestDoc.WriteTo(myWriter);
myWriter.Close();
如果必须将节点作为根节点的子节点插入,则上面的代码运行良好。但我想将节点作为任何其他节点的子节点插入。我该怎么办?