XSD Composite Elements Only Text
- Previous Page XSD Composite Elements Only Elements
- Next Page XSD Mixed Content
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 composite type, whose content is defined as integer values, 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 'shoesize' element's type attribute refer to this name (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>
- Previous Page XSD Composite Elements Only Elements
- Next Page XSD Mixed Content