Compound elements that contain only text can contain text and attributes. This type contains only simple content (text and attributes), so we will add simpleContent elements to this content. When using simple content, we have to define an extension or qualification within the simpleContent element, like this: 提示: Use extension or restriction elements to extend or restrict the basic simple types of elements. Here is an example of a XML element, “shoesize”, which contains only text: The following example declares a compound type whose content is defined as an integer value, and the “shoesize” element contains an attribute named “country”: We can also set a name for the complexType element and have the type attribute of the “shoesize” element refer to this name (by using this method, several elements can refer to the same compound type):A compound element that contains only text ¶
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
或者:
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<shoesize country="france">35</shoesize>
<xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>