共用方式為


SimpleContent Element Binding Support

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

Simple content extension is always fully expressed through class definitions in the .NET Framework. Simple content restriction is not recognized.

Explanation

The XML Schema definition language uses the <simpleContent> element to define a complex type that does not contain child elements. A complex type containing 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.

Xsd.exe does not recognize simple content restriction. Simple content extension is always fully expressed through class definitions in the .NET Framework. When generating source code from an XML Schema document, Xsd.exe produces a public field of a type corresponding 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.

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, corresponding to an XSD document, that defines complex types containing simple content.

Example

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>

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;
}

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>

See Also

Reference

XmlSchemaSimpleContent