Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML Schema Composite Elements - Text only


May 28, 2021 XML Schema


Table of contents


XSD contains only text

In The type of XML Schema composite element, including text-only composite elements.

Text-only composite elements can contain text and properties.


A composite element that contains only text

This type contains only simple content (text and properties), so we'll add a simpleContent element to this content. When using simple content, we have to 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>

Tip: Use the extension or restriction element to extend or limit the basic simple type of the element. Here's an example of an XML element, "shoesize," that 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 a property 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 have the type property of the "shoesize" element refer to the name (by using this method, several elements can refer to 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>

XML Schema composite element types can also contain both properties, elements, and text, i.e., composite elements that blend content types, which you can refer to in the next section for more information.