关于传递XML文档的问题。
做了一个WEB SERVICE服务,在传入的XML 文档的根上添加一个时间属性。如下:
[WebMethod]
public XmlElement xmltester(XmlElement root)
{root.SetAttribute("dataprocessed",System.DateTime.Now.ToUniversalTime().ToString("r"));
return root;
}
然后作乐一个客户程序,将修改后的文档根元素替换原来的根元素,并保存。程序如下:
XmlDocument doc=new XmlDocument();
doc.Load(@"F:\c#practise\xmltohtml\personnel.xml");
XmlElement root=doc.DocumentElement; XmlElement newroot;
newroot=mywebsvc.xmltester(root);
doc.ReplaceChild(newroot,doc.DocumentElement);
doc.Save(@"F:\c#practise\soapclient\personnel.xml");
运行时出错:
未处理的“System.ArgumentException”类型的异常出现在 system.xml.dll 中
其他信息:要插入的节点出自不同的文档上下文。
请问如何修改?