XSD Text-only


A text-only complex element can contain text and attributes.


Text-only complex element

This type contains only simple content (text and attributes), so we need to add a simpleContent element to this content. When using simple content, we must define an extension or restriction 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>

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 contains only 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 has 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 assign a name to the complexType element and let the type attribute of the "shoesize" element refer to that 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>
Other Extensions