XmlAttributeOverrides.Item Property (Type)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the object associated with the specified, base-class, type.

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

Public ReadOnly Property Item (
	type As Type
) As XmlAttributes


Type: System.Type

The base class Type that is associated with the collection of attributes you want to retrieve.

Property Value

Type: System.Xml.Serialization.XmlAttributes

An XmlAttributes that represents the collection of overriding attributes.

Use this overload to return an XmlAttributes object that contains attributes for an XmlRootAttribute or XmlTypeAttribute object.

If the XmlAttributes object contains objects that override an XmlArrayAttribute, XmlArrayItemAttribute, XmlElementAttribute, XmlEnumAttribute, or XmlAttributeAttribute, you must use the overload that specifies the overridden member as well as the type.

The following example creates an XmlAttributeOverrides object, an XmlAttributes object, and an XmlRootAttribute object. The example assigns the XmlRootAttribute to the XmlRoot property of the XmlAttributes object, and adds the XmlAttributes object to the XmlAttributeOverrides object. Lastly, the example gets the XmlAttributes object by passing the Type of the serialized class to the XmlAttributeOverrides object. In this example, the Type is Group.

' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample

    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim attrs As New XmlAttributes()
        Dim xOver As New XmlAttributeOverrides()

        Dim xRoot As New XmlRootAttribute()
        ' Set a new Namespace and ElementName for the root element.
        xRoot.Namespace = "http://www.cpandl.com"
        xRoot.ElementName = "NewGroup"
        attrs.XmlRoot = xRoot

        xOver.Add(GetType(Group), attrs)

        ' Get the XmlAttributes object, based on the type.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group))

        ' Print the Namespace and ElementName of the root.

        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top