Sax Parser
Sax Parser
using System.IO;
using System.Xml;
namespace SaxParserExample
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("data.xml");
root.AppendChild(newElement);
doc.Save("data.xml");
}
}
}
In this example, the XmlDocument object doc loads the data.xml file. The root node
of the document is accessed and stored in the root variable. A new XmlElement is
created using the CreateElement method of the doc object and the element's inner
text is set to "new value". The new element is then added to the end of the root
node using the AppendChild method. Finally, the changes to the document are saved
back to the data.xml file using the Save method.
using System;
using System.IO;
using System.Xml;
namespace SaxParserExample
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("bookDetails.xml");
bookNode.Attributes.Append(newAttribute);
doc.Save("bookDetails.xml");
}
}
}
In this example, the XmlDocument object doc loads the bookDetails.xml file. The
node for the book with the title "The Great Gatsby" is selected using the
SelectSingleNode method. A new XmlAttribute is created using the CreateAttribute
method of the doc object and its value is set to "1925". The new attribute is then
added to the book node using the Append method of the Attributes property. Finally,
the changes to the document are saved back to the bookDetails.xml file using the
Save method.