XmlAnyAttributeAttribute Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Specifies that the member (a field that returns an array of XmlAttribute objects) can contain any XML attributes.

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Xml.Serialization..::.XmlAnyAttributeAttribute

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

Syntax

<AttributeUsageAttribute(AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.Property Or AttributeTargets.ReturnValue, AllowMultiple := False)> _
Public Class XmlAnyAttributeAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.Property|AttributeTargets.ReturnValue, AllowMultiple = false)]
public class XmlAnyAttributeAttribute : Attribute

The XmlAnyAttributeAttribute type exposes the following members.

Constructors

  Name Description
XmlAnyAttributeAttribute Constructs a new instance of the XmlAnyAttributeAttribute class.

Top

Methods

  Name Description
Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
GetType Gets the Type of the current instance. (Inherited from Object.)
Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

Use the XmlAnyAttributeAttribute to contain arbitrary data (as XML attributes) that is sent as part of an XML document, such as, metadata sent as part of the document.

Apply the XmlAnyAttributeAttribute to a field that returns an array of XmlAttribute or XmlNode objects. When the Deserialize method of the XmlSerializer class is called, all XML attributes that do not have a corresponding member in the class being deserialized are collected in the array. After deserialization, you can iterate through the collection of XmlAttribute items to process the data.

The UnknownNode()()() and UnknownAttribute()()() events of the XmlSerializer do not occur if you apply the XmlAnyAttributeAttribute to a member of a class.

Note

You can use the word XmlAnyAttribute in your code instead of the longer XmlAnyAttributeAttribute.

For more information about using attributes, see [30386922-1e00-4602-9ebf-526b271a8b87].

Examples

The following example collects all unknown attributes into an array of XmlAttribute objects. To try the example, create a file named UnknownAttributes.xml that contains the following 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>

Version Information

Windows Phone OS

Supported in: 8.1, 8.0

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.

See Also

Reference

System.Xml.Serialization Namespace

XmlAnyElementAttribute

XmlSerializer

XmlAttributes

Other Resources

[8c63200d-db63-4a03-a93d-21641623df62]

[5cc1c0b0-f94b-4525-9a41-88a582cd6668]

[47d4c39d-30e1-4c7b-8a2e-301325390647]

[eec46337-9696-435b-a375-dc5effae6992]

[a6e6e65c-347f-4494-9457-653bf29baac2]