// create the document
XmlDocument xmlDoc = new XmlDocument();
// load the file
xmlDoc.Load(filename);
// goto the node
XmlNode node = xmlDoc.SelectSingleNode("/path/path/node");
// append new node
XmlNode newNode = node.AppendChild(xmlDoc.CreateElement("Element"));
// create attribute
XmlAttribute at =
newNode.Attributes.Append(xmlDoc.CreateAttribute(" test"));
// set value
at.value = "value";
On Fri, 21 Jan 2005 20:03:26 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:
Newbie wrote:
I am trying to insert items to an xml file:
1. Search for the right node where the new item is to be added as a child.
2. Add the new item with its attributes.
I am looking at XPathNavigator and XMLReader but cant find the functions to
do the job.
Those don't help to manipulate XML, if the XML fits into memory then
XmlDocument in System.Xml is a nice way to read in the whole XML
document into a tree structure of nodes which allows creation and
insertion of new nodes and later saving of the whole tree.