This section describes a tutorial example on how to define an element that accepts attributes and text content without sub elements using complexType with simpleContent.
A complex element with simple content is an element with text content and attributes, but no sub (child) element.
This type of element can be declared with a "complexType" datatype with "simpleContent" containing some "attribute"s.
A good example of complex elements with simple content is the <textarea> element in HTML documents.
It accepts a text string as the content with no sub (child) element and some attributes.
Rule 1. The "complexType" component defines a datatype for a complex element.
Rule 2. The "simpleContent" component used inside "complexType" specifies that the complex element
should not have any sub (child) element.
Rule 3. The "extension" component inside "simpleContent" extends the specified base datatype for the content
to include "attribute" declarations.
Rule 4. Each "attribute" component inside "extension" defines an additional attribute for the base datatype.
Here is an sample schema, complexType_simpleContent.xsd, that defines <textarea> to accept simple content
and 3 attributes:
Let's try this schema on a sample XML document, complexType_simpleContent.xml, with some errors:
>type complexType_simpleContent.xml
<?xml version="1.0"?>
<textarea name="comment" cols="50" rows="l">
This book is <b>really</b> helpful...
</textarea>
>java XsdSchemaValidator complexType_simpleContent.xsd
complexType_simpleContent.xml
Error:
Line number: 2
Column number: 45
Message: cvc-datatype-valid.1.2.1: 'l' is not a valid value
for 'integer'.
Error:
Line number: 2
Column number: 45
Message: cvc-attribute.3: The value 'l' of attribute 'rows' on
element 'textarea' is not valid with respect to its type,
'positiveInteger'.
Error:
Line number: 4
Column number: 12
Message: cvc-complex-type.2.2: Element 'textarea' must have no
element [children], and the value must be valid.
Failed with errors: 3