Extension Element Binding SupportÂ
The .NET Framework provides binding support for the <extension> element.
The Xsd.exe tool generates a base class, corresponding to the value of the base attribute, only for complex content, not simple content.
Explanation
The XML Schema definition language enables the deriving of new data types from base types through both extension and restriction. Extension is always used to derive complex types. The extension can be based on simple content or complex content differentiated as follows:
Simple content: Uses the XPath
complexType/simpleContent/extension
. The derived complex type does not contain child elements, only simple content—either attributes or body text, or both.Complex content: Uses the XPath
complexType/complexContent/extension
. Both the derived and base complex types contain child elements. They can also contain attributes and body text.
XML Schema type extensions always are fully expressed through class definitions in the .NET Framework. How Xsd.exe generates source code from an XML Schema document depends on whether the extension is based on simple content or complex content, as follows:
Simple content: Xsd.exe produces a new class with a public field of a type corresponding to the base data type, specified by the base attribute of the <extension> element. For the bindings between built-in simple types in the XML Schema and .NET Framework types, see Data Type Support between XML Schema (XSD) Types and .NET Framework Types.
Complex content: Xsd.exe produces a class corresponding to the base data type, specified by the base attribute of the <extension> element, and a class for the derived data type. The latter class inherits from the former, using a class declaration such as the following:
public class DerivedClass : BaseClass
.
Xsd.exe would preserve either kind of extension on a round-trip translation from XML schema to classes and back to a new XML Schema document.
For an example of simple content extension, see the <simpleContent> element.
Possible Attributes | Binding Support |
---|---|
base |
The <extension> element requires a base attribute, whose value is the qualified name of the base data type. For simple content extension, the Xsd.exe tool produces a public field from the base attribute's value. For complex content extension, Xsd.exe produces a base class from the base value. See the preceding text. |
id |
The Xsd.exe utility ignores the id attribute, which is intended to provide a unique identifier. |
Possible parent elements: <complexContent>, <simpleContent>
Possible child elements: <all>, <annotation>, <anyAttribute>, <attribute>, <attributeGroup>, <choice>, <group>, <sequence>
See Also
Reference
XmlSchemaComplexContentExtension
XmlSchemaSimpleContentExtension