<xsd:simpleContent> Element
Contains extensions or restrictions on a complexType element with character data or a simpleType element as content and contains no elements.
<simpleContent
id = ID
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | extension))
</simpleContent>
Attributes
id
The ID of this element. The id value must be of type ID and be unique within the document containing this element.Optional.
Element Information
Number of occurrences |
One time |
Parent elements |
|
Contents |
Optional — annotation Required — One and only one of the following elements: restriction (simpleContent), or extension (simpleContent). |
Remarks
The simpleContent element enables you to specify an element as containing a simpleType with no elements but enables you to restrict the value of the element's content or extend the element with attributes. For example, the following element declaration does not allow for adding attributes (such as sizing).
<xs:element name="shoeSize" type="xs:decimal"/>
Example
Using the simpleContent element, the following element declaration contains a complexType element that defines the content of the element as a decimal type with a single attribute (sizing).
<xs:element name="shoeSize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="sizing">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="US"/>
<xs:enumeration value="European"/>
<xs:enumeration value="UK"/>
<xs:enumeration value="Japan"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Simple content must be defined in one of the following ways.
restriction element |
Restricts the range of values for the element to a subset of those for inherited simpleType. |
extension element |
Extends the simpleType content of the element by adding attributes. |
Examples
The following example shows an element (generalPrice) declared using an anonymous complexType (one without a name) with its content defined as a decimal data type and with a currency attribute.
<xs:element name="generalPrice">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Other Resources
For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502\#element-all.