SimpleContent Element Binding Support
This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation.
The .NET Framework provides partial binding support for the <simpleContent> element.
The simple content extension is always fully expressed through class definitions in the .NET Framework. The simple content restriction is not recognized by Xsd.exe.
Explanation
The XML Schema definition language uses the <simpleContent> element to define a complex type that does not contain child elements. A complex type that contains simple content (either attributes or body text, or both) is derived from a base type through either extension or restriction, using either an <extension> or <restriction> element under the <simpleContent> element.
When generating source code from an XML Schema document, Xsd.exe produces a public field of a type that corresponds to the base 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" in the .NET Framework Developer's Guide.
Simple content extension and restriction are represented in the Schema Object Model through the classes XmlSchemaSimpleContentExtension and XmlSchemaSimpleContentRestriction, respectively, as well as through the XmlSchemaSimpleContent class.
Objects of these classes can be used to programmatically create a schema object model, which corresponds to an XSD document, which defines complex types that contain simple content.
Example
The following code is the input XML Schema document.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
<xsd:element name="Distance">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:float">
<xsd:attribute name="units" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The C# class generated from the preceding XML Schema document.
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://example.org/", IsNullable=false)]
public class Distance {
[System.Xml.Serialization.XmlAttributeAttribute()]
public string units;
[System.Xml.Serialization.XmlTextAttribute()]
public System.Single Value;
}
The XML Schema element and complex type generated from an assembly compiled from the preceding C# source.
<xs:element name="Distance" type="tns:Distance" />
<xs:complexType name="Distance">
<xs:simpleContent>
<xs:extension base="xs:float">
<xs:attribute name="units" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Possible Attributes | Binding Support |
---|---|
id |
The Xsd.exe utility ignores the id attribute, which is intended to provide a unique identifier. |
Possible parent elements: <complexType>
Possible child elements: <annotation>, <extension>, <restriction>