Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlNodeEventArgs Class

Provides data for the UnknownNode event.

For a list of all members of this type, see XmlNodeEventArgs Members.

System.Object
   System.EventArgs
      System.Xml.Serialization.XmlNodeEventArgs

[Visual Basic]
Public Class XmlNodeEventArgs
   Inherits EventArgs
[C#]
public class XmlNodeEventArgs : EventArgs
[C++]
public __gc class XmlNodeEventArgs : public EventArgs
[JScript]
public class XmlNodeEventArgs extends EventArgs

Thread Safety

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

Remarks

For more information about handling events, see Consuming Events.

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

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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()
      t.DeserializeObject("UnknownNodes.xml")
   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)
      fs.Close()
   End Sub
   
   Protected 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)
      Console.WriteLine()
   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" 

'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>

[C#] 
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>
*/   

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

public __gc class Group{
   // Only the GroupName field will be known.
public:
   String* GroupName;
};

public __gc class Test{
public:
   static void main(){
      Test* t = new Test();
      t->DeserializeObject(S"UnknownNodes.xml");
   }

private:
   void DeserializeObject(String* filename){
      XmlSerializer* mySerializer = new XmlSerializer(__typeof(Group));
      FileStream* fs = new FileStream(filename, FileMode::Open);
      mySerializer->UnknownNode += new 
         XmlNodeEventHandler(this, &Test::serializer_UnknownNode);
      Group* myGroup = dynamic_cast<Group*> (mySerializer->Deserialize(fs));
      fs->Close();
   }
protected:
   void serializer_UnknownNode
      (Object* /*sender*/, XmlNodeEventArgs* e){
         Console::WriteLine(S"UnknownNode Name: {0}",e->Name);
         Console::WriteLine(S"UnknownNode LocalName: {0}",e->LocalName);
         Console::WriteLine(S"UnknownNode Namespace URI: {0}",e->NamespaceURI);
         Console::WriteLine(S"UnknownNode Text: {0}",e->Text);

         XmlNodeType myNodeType = e->NodeType;
         Console::WriteLine(S"NodeType: {0}", __box(myNodeType));

         Group* myGroup = dynamic_cast<Group*> (e->ObjectBeingDeserialized);
         Console::WriteLine(S"GroupName: {0}",myGroup->GroupName);
         Console::WriteLine();
      }
};

int main()
{
   Test::main();
}
/* 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>
*/   

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Xml.Serialization

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Xml (in System.Xml.dll)

See Also

XmlNodeEventArgs Members | System.Xml.Serialization Namespace | Deserialize | XmlSerializer | XmlAttributeEventArgs

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft