Skip to main content

XSD Text Only Elements

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

Complex Text-Only Elements

We can declare Complex Text-only elements using the following methods:

Using SimpleContent

Define complexType with simpleContent. SimpleContent can use extension/restriction element to increase/reduce scope of base type of the element.

simpleContent with extension
<xs:element name="my-name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

or

simpleContent with restriction
<xs:element name="my-name">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>

Using ComplexType alone

Define an element of complexType with the required attribute element only.

<xs:element name="my-name" type="my-type">

<xs:complexType name="my-type">
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>