Export (0) Print
Expand All

XmlAnyElementAttribute Class

Specifies that the member (a field that returns an array of XmlElement or XmlNode objects) contains objects that represent any XML element that has no corresponding member in the object being serialized or deserialized.

System.Object
  System.Attribute
    System.Xml.Serialization.XmlAnyElementAttribute

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

[<AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue, AllowMultiple = true)>]
type XmlAnyElementAttribute =  
    class
        inherit Attribute
    end

The XmlAnyElementAttribute type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryXmlAnyElementAttribute()Initializes a new instance of the XmlAnyElementAttribute class.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryXmlAnyElementAttribute(String)Initializes a new instance of the XmlAnyElementAttribute class and specifies the XML element name generated in the XML document.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryXmlAnyElementAttribute(String, String)Initializes a new instance of the XmlAnyElementAttribute class and specifies the XML element name generated in the XML document and its XML namespace.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryNameGets or sets the XML element name.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryNamespaceGets or sets the XML namespace generated in the XML document.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryOrderGets or sets the explicit order in which the elements are serialized or deserialized.
Public propertyTypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibraryFinalizeAllows 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 FrameworkSupported by Portable Class LibraryGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public methodSupported by the XNA FrameworkMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibraryMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate method_Attribute.GetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.InvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top

Use the XmlAnyElementAttribute to contain arbitrary data (as XML elements) that can be sent as part of an XML document, such as metadata sent as part of the document.

Apply the XmlAnyElementAttribute to a field that returns an array of XmlElement or XmlNode objects. Such a field can be used in two ways, depending on whether an object is being serialized or deserialized. When serialized, the object is generated as XML elements or nodes, even though they have no corresponding member (or members) in the object being serialized. If you specify a Name property value when applying the attribute, all XmlElement or XmlNode objects inserted into the array must have the same element name and default namespace, or an exception is thrown. If you set the Namespace property value, you must set the Name property as well, and the XmlElement or XmlNode objects must also have the same name and namespace values. If no Name value is specified, the XmlElement or XmlNode objects can have any element name.

When you call the Deserialize method of the XmlSerializer class, all elements that do not have a corresponding member in the object being deserialized are collected in the array. After deserialization, iterate through the collection of XmlElement items to process the data. If you specify a Name value, the array contains only XML elements with that name. If you do not specify a Name value, the array contains all elements that have no corresponding member in the class. If a class contains more than one field to which the attribute is applied, use the Name, or Name and Namespace properties to differentiate between the contents of the arrays. If such a class (with multiple fields) also contains one field that has no differentiating property values set (in other words, Name and Namespace) during deserialization, this array contains any unknown XML elements that are not already contained in the other arrays. If a class contains more than one field that does not have a differentiating Name, or Name and Namespace value set, the behavior during deserialization is unspecified.

You can also apply the XmlAnyElementAttribute to a field that returns a single XmlElement object. If you do so, you must use the properties and methods of the XmlElement class to recursively iterate through the unknown elements.

You can apply multiple instances of the XmlAnyElementAttribute to a class member, but each instance must have a distinct Name property value. Or, if the same Name property is set for each instance, a distinct Namespace property value must be set for each instance.

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

NoteNote

You can use the word XmlAnyElement in your code instead of the longer XmlAnyElementAttribute.

For more information about using attributes, see Extending Metadata Using Attributes.

The following example applies the XmlAnyElementAttribute to a field named AllElements that returns an array of XmlElement objects.

No code example is currently available or this language may not be supported.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Community Additions

ADD
Show:
© 2014 Microsoft