Freigeben über


AnyAttribute Element Binding Support 

The .NET Framework provides partial binding support for the <anyAttribute> element.

When generating source code from an XML Schema document, Xsd.exe translates the <anyAttribute> element into a field of type System.Xml.XmlAttribute, with an attribute XmlAnyAttributeAttribute.

Explanation

The <anyAttribute> wildcard allows any attribute (an attribute of any name or simple type) to appear in a given element in an XML instance document, with some constraints.

When generating source code from an XML Schema document, Xsd.exe translates the <anyAttribute> element into a field of type System.Xml.XmlAttribute, with an attribute XmlAnyAttributeAttribute. This attribute allows a class to represent arbitrary XML attributes without binding them to non-XML types identified by other possible fields or properties of the class.

When generating an XML Schema document from a set of classes in an assembly, Xsd.exe performs the reverse translation: a field or property of type System.Xml.XmlAttribute with an attribute XmlAnyAttributeAttribute is translated into an <anyAttribute> element.

namespace and processContents Attributes

During generation of XML Schema definitions or classes, the namespace and processContents attributes are ignored. This means that, whatever those attribute values are in an original XML Schema definition, when Xsd.exe generates classes from that definition and then generates another XML schema from those classes, the generated XML schema's <anyAttribute> element no longer has those attributes. Therefore, the latter schema reverts to the following default values:

  • namespace="##any": The namespace attribute specifies the namespaces in which the attribute must be defined. A value of ##any allows any namespace.

  • processContents="strict": When validating an instance XML document for conformance to its specified XML schema, make sure that all element types are validated according to the specified namespace(s). If an element type is not recognized, validation fails.

Likewise, during deserialization from XML documents to objects, the namespace and processContents attributes are ignored. Instead, the XmlSerializer class behaves as though the two attributes were fixed to the following values:

  • namespace="##any": This is the default value.

  • processContents="lax": When validating an instance XML document for conformance to its specified XML schema, validate the attribute only if its namespace can be obtained; otherwise, make sure an unrecognized attribute consists of well-formed XML.

Note

Even though at run time the .NET Framework assumes processContents="lax", at deployment time the .NET Framework generates XML Schema definitions where the default processContents="strict" is implicitly specified.

Xsd.exe and the XmlSerializer class provide the same bindings for the namespace and processContents attributes when they appear in the <any> element.

Possible Attributes Binding Support

id

The Xsd.exe utility ignores the id attribute, which is intended to provide a unique identifier.

namespace

See the section namespace and processContents Attributes within this topic.

processContents

See the section namespace and processContents Attributes within this topic.

Possible parent elements: <attributeGroup>, <complexType>, <extension>, <restriction>

Possible child elements: <annotation>

See Also

Reference

XmlSchemaAnyAttribute