开发者

Updating XML file c#

I want to replace a xml node that is not a child of the root element. how c开发者_高级运维an I do it?


If you use .Net 3.5 you can use System.Xml.Linq:

XDocument x = XDocument.Load("filename.xml");
x.Root.GetElement("ElementName").SetValue("value");
x.Save("filename.xml");


You could use the XmlDocument.ImportNode, and XmlElement.AppendChild to do this.

public void AppendNodeToTarget(XmlElement targetElement, 
    XmlDocument targetDocument, XmlNode node)
{
    XmlNode nodeToAppend = targetDocument.ImportNode(node, true);
    targetElement.AppendChild(nodeToAppend);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜