Handles NodeChanged, NodeChanging, NodeInserted, NodeInserting, NodeRemoved and NodeRemoving events.
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim mySample As Sample = New Sample()
mySample.Run("book.xml")
End Sub
Public Sub Run(ByVal args As String)
Dim doc As XmlDocument = New XmlDocument()
doc.Load(args)
AddHandler doc.NodeChanged, AddressOf MyNodeChangedEvent
AddHandler doc.NodeInserted, AddressOf MyNodeInsertedEvent
doc.DocumentElement.LastChild.InnerText = "5.95"
Dim newElem As XmlElement = doc.CreateElement("style")
newElem.InnerText = "hardcover"
doc.DocumentElement.AppendChild(newElem)
Console.WriteLine(doc.OuterXml)
End Sub
Private Sub MyNodeChangedEvent(ByVal source As Object, ByVal args As XmlNodeChangedEventArgs)
Console.Write(args.Node.Name)
If Not (args.Node.Value Is Nothing) Then
Console.WriteLine(" with value {0}", args.Node.Value)
Else
Console.WriteLine("")
End If
End Sub
Private Sub MyNodeInsertedEvent(ByVal source As Object, ByVal args As XmlNodeChangedEventArgs)
Console.Write(args.Node.Name)
If Not (args.Node.Value Is Nothing) Then
Console.WriteLine(" with value {0}", args.Node.Value)
Else
Console.WriteLine("")
End If
End Sub
End Class
Related examples in the same category