System.Xml.Serialization.XmlNodeEventArgs Class

Assembly: System.Xml.dll
Namespace: System.Xml.Serialization
Summary
Provides data for the XmlSerializer.UnknownNode event.
C# Syntax:
public class XmlNodeEventArgs : EventArgs
Remarks
For more information about handling events, see the conceptual topic at MSDN: eventsoverview.

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

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

public class Group{
   // Only the GroupName field will be known.
   public string GroupName;
}

public class Test{
   static void Main(){
      Test t = new Test();
      t.DeserializeObject("UnknownNodes.xml");
   }

   private void DeserializeObject(string filename){
      XmlSerializer mySerializer = new XmlSerializer(typeof(Group));
      FileStream fs = new FileStream(filename, FileMode.Open);
      mySerializer.UnknownNode += new 
      XmlNodeEventHandler(serializer_UnknownNode);
      Group myGroup = (Group) mySerializer.Deserialize(fs);
      fs.Close();
   }
   protected void serializer_UnknownNode
   (object sender, XmlNodeEventArgs e){
      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);

      XmlNodeType myNodeType = e.NodeType;
      Console.WriteLine("NodeType: {0}", myNodeType);
 
      Group myGroup = (Group) e.ObjectBeingDeserialized;
      Console.WriteLine("GroupName: {0}", myGroup.GroupName);
      Console.WriteLine();
   }
}
/* 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" 

xmlns:cp="http://www.cpandl.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>
</Group>
*/   

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

System.Xml.Serialization.XmlNodeEventArgs Member List:

Public Properties
LineNumber Read-only

Gets the line number of the unknown XML node.
LinePosition Read-only

Gets the position in the line of the unknown XML node.
LocalName Read-only

Gets the XML local name of the XML node being deserialized.
Name Read-only

Gets the name of the XML node being deserialized.
NamespaceURI Read-only

Gets the namespace URI that is associated with the XML node being deserialized.
NodeType Read-only

Gets the type of the XML node being deserialized.
ObjectBeingDeserialized Read-only

Gets the object being deserialized.
Text Read-only

Gets the text of the XML node being deserialized.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Serialization.XmlNodeEventArgs Member Details

Property: LineNumber (read-only)
Summary
Gets the line number of the unknown XML node.
C# Syntax:
public int LineNumber {get;}
Example
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

public class Group{
   // Only the GroupName field will be known.
   public string GroupName;
}

public class Test{
   static void Main(){
      Test t = new Test();
      t.DeserializeObject("UnknownNodes.xml");
   }

   private void DeserializeObject(string filename){
      XmlSerializer mySerializer = new XmlSerializer(typeof(Group));
      FileStream fs = new FileStream(filename, FileMode.Open);
      mySerializer.UnknownNode += new 
      XmlNodeEventHandler(serializer_UnknownNode);
      Group myGroup = (Group) mySerializer.Deserialize(fs);
      fs.Close();
   }
   protected void serializer_UnknownNode
   (object sender, XmlNodeEventArgs e){
      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);

      XmlNodeType myNodeType = e.NodeType;
      Console.WriteLine("NodeType: {0}", myNodeType);
 
      Group myGroup = (Group) e.ObjectBeingDeserialized;
      Console.WriteLine("GroupName: {0}", myGroup.GroupName);
      Console.WriteLine();
   }
}
/* 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" 

xmlns:cp="http://www.cpandl.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>
</Group>
*/   

    

Return to top


Property: LinePosition (read-only)
Summary
Gets the position in the line of the unknown XML node.
C# Syntax:
public int LinePosition {get;}
Example
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

public class Group{
   // Only the GroupName field will be known.
   public string GroupName;
}

public class Test{
   static void Main(){
      Test t = new Test();
      t.DeserializeObject("UnknownNodes.xml");
   }

   private void DeserializeObject(string filename){
      XmlSerializer mySerializer = new XmlSerializer(typeof(Group));
      FileStream fs = new FileStream(filename, FileMode.Open);
      mySerializer.UnknownNode += new 
      XmlNodeEventHandler(serializer_UnknownNode);
      Group myGroup = (Group) mySerializer.Deserialize(fs);
      fs.Close();
   }
   protected void serializer_UnknownNode
   (object sender, XmlNodeEventArgs e){
      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);

      XmlNodeType myNodeType = e.NodeType;
      Console.WriteLine("NodeType: {0}", myNodeType);
 
      Group myGroup = (Group) e.ObjectBeingDeserialized;
      Console.WriteLine("GroupName: {0}", myGroup.GroupName);
      Console.WriteLine();
   }
}
/* 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" 

xmlns:cp="http://www.cpandl.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>
</Group>
*/   

    

Return to top


Property: LocalName (read-only)
Summary
Gets the XML local name of the XML node being deserialized.
C# Syntax:
public string LocalName {get;}
Remarks
The XmlNodeEventArgs.LocalName property returns the local name (also known as a local part) of an XML qualified name. The XmlNodeEventArgs.LocalName property conforms to the 1999 http://www.w3.org specification Namespaces in XML.
Example
The following example prints the XmlNodeEventArgs.LocalName of an unknown node of an unknown XML node that is encountered when calling the XmlSerializer class's XmlSerializer.Deserialize method.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   Console.WriteLine
   ("UnknownNode LocalName: " + e.LocalName);
}


    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Property: Name (read-only)
Summary
Gets the name of the XML node being deserialized.
C# Syntax:
public string Name {get;}
Example
The following example prints the name of the unknown node that caused the XmlSerializer.UnknownNode event to occur.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   Console.WriteLine
   ("UnknownNode Name: " + e.Name);
}
   

    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Property: NamespaceURI (read-only)
Summary
Gets the namespace URI that is associated with the XML node being deserialized.
C# Syntax:
public string NamespaceURI {get;}
Example
The following example prints the URI of the unknown XML node that caused the XmlSerializer.UnknownNode event to occur.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   Console.WriteLine
   ("UnknownNode Namespace URI: " + e.NamespaceURI);
}
   

    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Property: NodeType (read-only)
Summary
Gets the type of the XML node being deserialized.
C# Syntax:
public XmlNodeType NodeType {get;}
Remarks
The XmlNodeType enumeration returns a description of the node being deserialized. For example, it returns "Comment" if the node is a comment.
Example
The following example prints a description of the unknown node that caused the XmlSerializer.UnknownNode event to occur.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   XmlNodeType myNodeType = e.NodeType;
   Console.WriteLine(myNodeType);
}
   

    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Property: ObjectBeingDeserialized (read-only)
Summary
Gets the object being deserialized.
C# Syntax:
public object ObjectBeingDeserialized {get;}
Example
The following example prints the value returned by the Object.ToString method when the XmlSerializer.Deserialize method encounters an unknown XML node.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   object o = e.ObjectBeingDeserialized;
   Console.WriteLine("Object being deserialized: " 
   + o.ToString());
       
}
   

    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Property: Text (read-only)
Summary
Gets the text of the XML node being deserialized.
C# Syntax:
public string Text {get;}
Example
The following example prints the text of the unknown XML node that caused the XmlSerializer.UnknownNode event to occur.
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
   Console.WriteLine
   ("UnknownNode Text: " + e.Text);
}
   

    
See also:
XmlSerializer.Deserialize | XmlSerializer

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlNodeEventArgs();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

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