Export (0) Print
Expand All

XmlAttributeEventArgs Class

Provides data for the UnknownAttribute event.

System.Object
  System.EventArgs
    System.Xml.Serialization.XmlAttributeEventArgs

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

'Declaration
Public Class XmlAttributeEventArgs _
	Inherits EventArgs

The XmlAttributeEventArgs type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkAttrGets an object that represents the unknown XML attribute.
Public propertyExpectedAttributesGets a comma-delimited list of XML attribute names expected to be in an XML document instance.
Public propertySupported by the XNA FrameworkLineNumberGets the line number of the unknown XML attribute.
Public propertySupported by the XNA FrameworkLinePositionGets the position in the line of the unknown XML attribute.
Public propertySupported by the XNA FrameworkObjectBeingDeserializedGets the object being deserialized.
Top

  NameDescription
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

For more information about handling events, see Events Overview (Windows Forms).

The UnknownAttribute event occurs only when you call the Deserialize method.

The following example deserializes a class named Group from a file named UnknownAttributes.xml. Whenever an element is found in the file that has no corresponding member in the class, the UnknownAttribute event occurs. To try the example, paste the following XML code into a file named UnknownAttributes.xml.

 <?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" GroupType = 'Technical' GroupNumber = '42' GroupBase = 'Red'>
   <GroupName>MyGroup</GroupName>
 </Group>
Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Xml.Schema
Imports Microsoft.VisualBasic

Public Class Group
   Public GroupName As String  
End Class 

Public Class Test
   Shared Sub Main()
      Dim t As Test = new Test()
      ' Deserialize the file containing unknown elements.
      t.DeserializeObject("UnknownAttributes.xml")
   End Sub 

   Private Sub Serializer_UnknownAttribute _
   (sender As Object , e As XmlAttributeEventArgs)
      Console.WriteLine("Unknown Attribute")
      Console.WriteLine(ControlChars.Tab & e.Attr.Name + " " & e.Attr.InnerXml)
      Console.WriteLine(ControlChars.Tab & e.LineNumber & ":"  & e.LineNumber)
      Console.WriteLine(ControlChars.Tab & e.LinePosition & ":"   & e.LinePosition)

      Dim x As Group = CType( e.ObjectBeingDeserialized, Group)
      Console.WriteLine (x.GroupName)
      Console.WriteLine (sender.ToString())
   End Sub 

   Private Sub DeserializeObject(filename As String)
      Dim ser As XmlSerializer = new XmlSerializer(GetType(Group))
      ' Add a delegate to handle unknown element events. 
      AddHandler ser.UnknownAttribute, _
      AddressOf Serializer_UnknownAttribute 
      ' A FileStream is needed to read the XML document. 
     Dim fs As FileStream  = new FileStream(filename, FileMode.Open)
     Dim g  As Group = CType(ser.Deserialize(fs),Group)
     fs.Close()
   End Sub 
End Class

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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