I am creating an XSD schema and I need to define complexType elements that are mixed (have both text and elements) but I need to require these to be non-empty. For simpleType there is minLength but I don't know how to (or if it is possible) to restrict this for a mixed complexType.
To illustrate the need, take the following examples in which there is a 'text' root element and the mixed complexType is 'name':
"<text></text>" <= Valid
"<text>His name was <name>John <unk/> Mal<del>c</del>kovich</name>.</text>" <= Valid
"<text>His name was <name>John Malkovich</name>.</text>" <= Valid
"<text>A person called <name></name> was outside.</text>" <= Invalid
Right now I have the following schema which gives valid to the last example, but I need it to be invalid. How can TextType be required to be non-empty?
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<!--==============-->
<!-- ROOT ELEMENT -->
<!--==============-->
<xs:element name="text">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="TextTypeChoice"/>
<xs:element name="name" type="NameType" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
<!--==============================-->
<!-- Group for Text type elements -->
<!--==============================-->
<xs:group name="TextTypeChoice">
<xs:choice>
<xs:element name="unk" type="EmptyType" maxOccurs="unbounded"/>
<xs:element name="del" type="RawTextType" maxOccurs="unbounded"/>
</xs:choice>
</xs:group>
<!--=============================-->
<!-- Definition of the Text type -->
<!--=============================-->
<xs:complexType name="TextType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="TextTypeChoice"/>
</xs:choice>
</xs:complexType><!--TextType-->
<!--=============================-->
<!-- Definition of the Name type -->
<!--=============================-->
<xs:complexType name="NameType">
<xs:complexContent>
<xs:extension base="TextType"/>
</xs:complexContent>
</xs:complexType><!--NameType-->
<!--===================-->
<!-- Type for raw text -->
<!--===================-->
<xs:simpleType name="RawTextType">
<xs:restriction base="xs:token">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType><!--RawTextType-->
<!--========================================-->
<!-- Type for empty / self-closing elements -->
<!--========================================-->
<xs:simpleType name="EmptyType">
<xs:restriction base="xs:string">
<xs:maxLength value="0"/>
</xs:restriction>
</xs:simpleType><!--EmptyType-->
</xs:schema>
name
to be non-empty? – kjhughesNameType
elements to be mixed recursively, and they can be empty, but they cannot contain other emptyNameType
elements? – kjhughes