XmlNodeChangedEventHandler Delegate


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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 Handling and Raising Events.

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

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
public ref class Sample
   void Run( String^ args )
      // Create and load the XML document.
      Console::WriteLine( "Loading file {0} ...", args );
      XmlDocument^ doc = gcnew XmlDocument;
      doc->Load( args );

      //Create the event handlers.
      doc->NodeChanged += gcnew XmlNodeChangedEventHandler( this, &Sample::MyNodeChangedEvent );
      doc->NodeInserted += gcnew XmlNodeChangedEventHandler( this, &Sample::MyNodeInsertedEvent );

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

      // Add a new element.
      XmlElement^ newElem = doc->CreateElement( "style" );
      newElem->InnerText = "hardcover";
      doc->DocumentElement->AppendChild( newElem );
      Console::WriteLine( "\r\nDisplay the modified XML..." );
      Console::WriteLine( doc->OuterXml );

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

   // Handle the NodeInserted event.
   void MyNodeInsertedEvent( Object^ /*src*/, XmlNodeChangedEventArgs^ args )
      Console::Write( "Node Inserted Event: <{0}> inserted", args->Node->Name );
      if ( args->Node->Value != nullptr )
         Console::WriteLine( " with value {0}", args->Node->Value );
            Console::WriteLine( "" );
// End class 

int main()
   Sample^ mySample = gcnew Sample;
   mySample->Run( "book.xml" );

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>

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top