System.Xml.Serialization.XmlNodeEventHandler Delegate

Assembly: System.Xml.dll
Namespace: System.Xml.Serialization
Summary
Represents the method that will handle the XmlSerializer.UnknownNode event of an XmlSerializer.
C# Syntax:
[Serializable]
public delegate void XmlNodeEventHandler(object sender, XmlNodeEventArgs e);
Parameters:
The declaration of your event handler must have the same parameters as the XmlNodeEventHandler delegate declaration.

sender

The source of the event.

e

An XmlNodeEventArgs that contains the event data.

Remarks
When you create an XmlNodeEventHandler delegate, you identify the method that will handle 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 the conceptual topic at MSDN: eventsdelegates.

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

Example
The following example creates an XmlSerializer, adds an event handler for the XmlSerializer.UnknownNode event, and deserializes an object.

    private void DeserializeItem(string filename) {
        XmlSerializer mySerializer = 
            new XmlSerializer(typeof(ObjectToDeserialize));
        // Add an instance of the delegate to the event.
        mySerializer.UnknownNode += new XmlNodeEventHandler
            (Serializer_UnknownNode);
        // A FileStream is needed to read the file to deserialize.
        FileStream fs = new FileStream(filename, FileMode.Open);
        ObjectToDeserialize o = (ObjectToDeserialize)mySerializer.Deserialize(fs);
    }
     
    protected void Serializer_UnknownNode
        (object sender, XmlNodeEventArgs e) {
        
        Console.WriteLine("UnknownNode Name: "
                          + e.Name);
        Console.WriteLine("UnknownNode LocalName: "
                          + e.LocalName);
        Console.WriteLine("UnknownNode Namespace URI: "
                          + e.NamespaceURI);
        Console.WriteLine("UnknownNode Text: "
                          + e.Text);
     
        object o = e.ObjectBeingDeserialized;
        Console.WriteLine("Object being deserialized " 
                          + o.ToString());
           
        XmlNodeType myNodeType = e.NodeType;
        Console.WriteLine(myNodeType);
    }


    
See also:
System.Xml.Serialization Namespace | XmlSerializer.Deserialize | XmlSerializer

Hierarchy:

Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.