XmlAnyAttributeAttribute Class

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.

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

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

[AttributeUsageAttribute(AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.Property|AttributeTargets.ReturnValue, AllowMultiple = false)]
public class XmlAnyAttributeAttribute : Attribute

The XmlAnyAttributeAttribute type exposes the following members.

  NameDescription
Public methodXmlAnyAttributeAttributeConstructs a new instance of the XmlAnyAttributeAttribute class.
Top

  NameDescription
Public methodEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote:

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].

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>

Windows Phone OS

Supported in: 8.1, 8.0

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:
© 2017 Microsoft