XML Schema Tuto...login
XML Schema Tutorial
author:php.cn  update time:2022-04-20 14:13:02

XML Schema composite element – ​​text only


XSD Text only


Text-only compound elements can contain text and attributes.


Text-only compound element

This type contains only simple content (text and attributes), so we want to add the simpleContent element to this content. When using simple content, we must define extensions or qualifications within the simpleContent element, like this:

<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
          ....
  </xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

Or:

<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
          ....
  </xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>

Tips: Please use extension or restriction elements to extend or restrict the basic simple type of an element. Here is an example of an XML element, "shoesize", which contains only text:

<shoesize country="france">35</shoesize>

The following example declares a composite type whose contents are defined as integer values, and the "shoesize" element contains an attribute named "country":

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

We can also set a name for the complexType element and let the type attribute of the "shoesize" element refer to this name (by using this method, several elements can reference the same composite type):

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

php.cn