Skip to content

XSD Text Only Elements

How to create XSD text-only elements using simpleContent with extension or restriction, and understand the proper structure for defining complex types with attributes.

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 extensionxml
<xs:element name="my-name">
	<xs:complexType>
		<xs:simpleContent>
			<xs:extension base="basetype">
				....
				....
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
</xs:element>

or

simpleContent with restrictionxml
<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>
Navigation