This article has been
excerpted from the book "A Programmer's Guide to ADO.NET in C#".
The XmlDataDocument events are useful when your application needs to notify you when changes are being made to an XmlDataDocument object. XmlDocument defines
XmlDataDocument events (see Table 9-6).
| EVENT | DESCRIPTION |
|
NodeChanged
|
Occurs when the
value of a node has been changed
|
|
NodeChanging
|
Occurs when the
value of a node is changing
|
|
NodeInserted
|
Occurs when a node
inserted into another node
|
|
NodeInserting
|
Occurs when a node
inserting to another node
|
|
NodeRemove
|
Occurs when a node
has been removed
|
|
NodeRemoving
|
Occurs when a node
is being removed
|
The XmlNodeChangedEventHandler method handles the events listed in Table 9-6.
The XmlNodeChangedEventHandler is as follows:
- public delegate void XmlNodeChangedEventHandler(object sender, XmlNodeChangedEventArgs e);
Where sender is the source of the event and e is an XmlNodeChangedEventArgs that
contains the event data. XmlNodeChangedEventArgs defines properties (see Table
9-7).
| PROPERTY | DESCRIPTION |
|
Action
|
Returns a value
indicating the type of node changed event
|
|
NewParent
|
Returns a value of
parent node after the operation is finished
|
|
Node
|
Returns the node
that is being added, removed, or changed
|
|
OldParent
|
Returns the value
of the parent node before the operation started
|
Listing 9-11. Handles XmlDataDocument events. The XmlDocumentBtn_Click method
creates event handlers for the NodeChanged, NodeInserted, and NodeRemoved
events. The MyNodeChangedEvent, MyNodeInsertEvent, and MyNodeRemoved event handlers execute when these events fire. I used LoadXml to load an XML fragment
and then used the ReplaceChild and RemoveChild methods to replace and remove document nodes.


Join the conversation! Your thoughts help the community grow.