I want to replace a xml node that is not a child of the root element. how can I do it?
+2
A:
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");
Jouke van der Maas
2010-05-13 12:30:29
and if it is not .Net 3.5?
Pila
2010-05-13 12:32:37
+2
A:
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);
}
code4life
2010-05-13 13:51:41
A:
If you want to know how to operate XML files, this link may help you. Xml operations