This documentation is archived and is not being maintained.

XmlNodeChangedEventHandler Delegate

Represents the method that handles NodeChanged, NodeChanging, NodeInserted, NodeInserting, NodeRemoved and NodeRemoving events.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public delegate void XmlNodeChangedEventHandler(
	Object sender,
	XmlNodeChangedEventArgs e


Type: System.Object
The source of the event.
Type: System.Xml.XmlNodeChangedEventArgs
An XmlNodeChangedEventArgs containing the event data.

When you create an XmlNodeChangedEventHandler delegate, you identify the method that handles the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Events and Delegates.

The following example shows how to handle the NodeChanged and NodeInserted events.

using System;
using System.IO;
using System.Xml;

namespace Microsoft.Samples.Xml
    public class Sample
        private const String filename = "book.xml";

        public static void Main()
            Sample mySample = new Sample();

        public void Run(String args)

            // Create and load the XML document.
            Console.WriteLine("Loading file {0} ...", args);
            XmlDocument doc = new XmlDocument();

            //Create the event handlers.
            doc.NodeChanged += new XmlNodeChangedEventHandler(this.MyNodeChangedEvent);
            doc.NodeInserted += new XmlNodeChangedEventHandler(this.MyNodeInsertedEvent);

            // Change the book price.
            doc.DocumentElement.LastChild.InnerText = "5.95";

            // Add a new element.
            XmlElement newElem = doc.CreateElement("style");
            newElem.InnerText = "hardcover";

            Console.WriteLine("\r\nDisplay the modified XML...");


        // Handle the NodeChanged event.
        private void MyNodeChangedEvent(Object source, XmlNodeChangedEventArgs args)
            Console.Write("Node Changed Event: <{0}> changed", args.Node.Name);
            if (args.Node.Value != null)
                Console.WriteLine(" with value  {0}", args.Node.Value);

        // Handle the NodeInserted event.
        private void MyNodeInsertedEvent(Object source, XmlNodeChangedEventArgs args)
            Console.Write("Node Inserted Event: <{0}> inserted", args.Node.Name);
            if (args.Node.Value != null)
                Console.WriteLine(" with value {0}", args.Node.Value);

    } // End class 

The example uses the file book.xml as input.

<!--sample XML fragment-->
<book genre='novel' ISBN='1-861003-78' misc='sale-item'>
  <title>The Handmaid's Tale</title>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.