XSD Composite Type - Only Text

A composite element containing only text can contain text and attributes.

Composite element containing only text

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

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

Or:

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

Tip:Please use the extension or restriction element to extend or restrict the basic simple type of the element.

Here is an example of an XML element, "shoesize", which only contains text:

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

The following example declares a complex type whose content is defined as an integer value, 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 refer to the same complex 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>