日期:2014-05-18 浏览次数:20865 次
XmlDocument doc = new XmlDocument(); doc.LoadXml("<employeeclass><firstname> tom </firstname><lastname> wang </lastname></employeeclass>"); XmlNode node = doc.FirstChild; XmlDocument doc2 = new XmlDocument(); doc2.Load("c:\\a.xml"); XmlNode root = doc2.SelectSingleNode("employees"); XmlNode newNode = doc2.ImportNode(node, true); root.AppendChild(newNode); doc2.Save("c:\\a.xml");
------解决方案--------------------
//楼主参考下,看看是不是这个意思.
XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("Employee.xml")); XmlNode objectNode = doc.SelectSingleNode("employees"); XmlDocumentFragment docFrag = doc.CreateDocumentFragment(); docFrag.InnerXml = "<employeeclass><firstname>tom</firstname><lastname> wang </lastname></employeeclass>"; objectNode.InsertAfter(docFrag, objectNode.LastChild); doc.Save(Server.MapPath("Employee.xml"));