XmlNodeEventArgs Class

Provides data for the UnknownNode event.

Namespace: System.Xml.Serialization
Assembly: System.Xml (in system.xml.dll)

Public Class XmlNodeEventArgs
	Inherits EventArgs
Dim instance As XmlNodeEventArgs

public class XmlNodeEventArgs extends EventArgs
public class XmlNodeEventArgs extends EventArgs
Not applicable.

For more information about handling events, see Consuming Events.

The UnknownNode event can occur only when you call the Deserialize method.

The following example uses the UnknownNode event of the XmlSerializer to print various properties of an unknown XML node that is encountered when calling the XmlSerializer class's Deserialize method.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

Public Class Group
   ' Only the GroupName field will be known.
   Public GroupName As String
End Class

Public Class Test
   Shared Sub Main()
      Dim t As Test = New Test()
   End Sub

   Private Sub DeserializeObject(filename As String )
      Dim mySerializer As XmlSerializer  = New XmlSerializer(GetType(Group))
      Dim fs As FileStream = New FileStream(filename, FileMode.Open)
      AddHandler mySerializer.UnknownNode, _
      AddressOf serializer_UnknownNode
      Dim myGroup As Group = _
      CType(mySerializer.Deserialize(fs), Group)
   End Sub
   Private Sub serializer_UnknownNode _
   (sender As object , e As XmlNodeEventArgs )
      Console.WriteLine _
      ("UnknownNode Name: {0}", e.Name)
      Console.WriteLine _
      ("UnknownNode LocalName: {0}" ,e.LocalName)
      Console.WriteLine _
      ("UnknownNode Namespace URI: {0}", e.NamespaceURI)
      Console.WriteLine _
      ("UnknownNode Text: {0}", e.Text)

      Dim myNodeType As XmlNodeType = e.NodeType
      Console.WriteLine("NodeType: {0}", myNodeType)
      Dim myGroup As Group = CType(e.ObjectBeingDeserialized, Group)
      Console.WriteLine("GroupName: {0}", myGroup.GroupName)
   End Sub
End Class
' Paste this XML into a file named UnknownNodes:
'<?xml version="1.0" encoding="utf-8"?>
'<Group xmlns:xsi="http:'www.w3.org/2001/XMLSchema-instance" 

'xmlns:xsd="http:'www.w3.org/2001/XMLSchema" xmlns:coho = "http:'www.cohowinery.com" 

'   <coho:GroupName>MyGroup</coho:GroupName>
'   <cp:GroupSize>Large</cp:GroupSize>
'   <cp:GroupNumber>444</cp:GroupNumber>
'   <coho:GroupBase>West</coho:GroupBase>
'   <coho:ThingInfo>
'      <Number>1</Number>
'      <Name>Thing1</Name>
'      <Elmo>
'         <Glue>element</Glue>
'      </Elmo>
'  </coho:ThingInfo>

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

public class Group
    // Only the GroupName field will be known.
    public String groupName;
} //Group

public class Test
    public static void main(String[] args)
        Test t = new Test();
    } //main

    private void DeserializeObject(String filename)
        XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType());
        FileStream fs = new FileStream(filename, FileMode.Open);
        mySerializer.add_UnknownNode(new XmlNodeEventHandler
        Group myGroup = (Group)mySerializer.Deserialize(fs);
    } //DeserializeObject

    private void SerializerUnknownNode(Object sender, XmlNodeEventArgs e)
        Console.WriteLine("UnknownNode Name: {0}", e.get_Name());
        Console.WriteLine("UnknownNode LocalName: {0}", e.get_LocalName());
        Console.WriteLine("UnknownNode Namespace URI: {0}",
        Console.WriteLine("UnknownNode Text: {0}", e.get_Text());

        XmlNodeType myNodeType = e.get_NodeType();
        Console.WriteLine("NodeType: {0}", myNodeType);

        Group myGroup = (Group)e.get_ObjectBeingDeserialized();
        Console.WriteLine("GroupName: {0}", myGroup.groupName);
    } //SerializerUnknownNode
} //Test
/* Paste this XML into a file named UnknownNodes:
<?xml version="1.0" encoding="utf-8"?>
<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:coho = "http://www.cohowinery.com" 



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions