Reputation: 719
I wrote the following xml-schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
vc:minVersion="1.0" vc:maxVersion="1.1">
<xs:element name="zoo_ct">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Tier">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="alter" type="xs:positiveInteger"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="säugetier_ct">
<xs:complexContent>
<xs:extension base="Tier">
<xs:element name="tragezeit" type="xs:positiveInteger"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="vogel_ct">
<xs:complexContent>
<xs:extension base="Tier">
<xs:element name="flugfähig" type="xs:boolean"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="pfleger_ct">
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:complexType>
<xs:complexType name="behausung_ct">
<xs:element name="bezeichnung" type="xs:string"/>
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:complexType>
<xs:complexType name="gebäude_ct">
<xs:complexContent>
<xs:extension base="behausung_ct">
<xs:element name="fläche" type="xs:double"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="teich_ct">
<xs:complexContent>
<xs:extension base="behausung_ct">
<xs:element name="wassertiefe" type="xs:double"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
However, when running this, it results in 6 error messages, each(!) of which is of the same type: something is supposed to be wrong with the element contained within the respective complexType:
The content of 'säugetier_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
The content of 'vogel_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
The content of 'pfleger_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
The content of 'behausung_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
The content of 'gebäude_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
The content of 'teich_ct' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
I do not understand what is supposed to be wrong with the respective elements. This is the simplest part of the code and I'm absolutely sure that this is the correct syntax.
Does anybody know what's going on here?
Upvotes: 1
Views: 1549
Reputation: 111491
In XSD, xs:complexType
and xs:extension
cannot have xs:element
as a direct child.
Here is your XSD with xs:sequence
wrappers added:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.0" vc:maxVersion="1.1">
<xs:element name="zoo_ct">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Tier">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="alter" type="xs:positiveInteger"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="säugetier_ct">
<xs:complexContent>
<xs:extension base="Tier">
<xs:sequence>
<xs:element name="tragezeit" type="xs:positiveInteger"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="vogel_ct">
<xs:complexContent>
<xs:extension base="Tier">
<xs:sequence>
<xs:element name="flugfähig" type="xs:boolean"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="pfleger_ct">
<xs:sequence>
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="behausung_ct">
<xs:sequence>
<xs:element name="bezeichnung" type="xs:string"/>
<xs:element name="zootier_ct" type="Tier" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="gebäude_ct">
<xs:complexContent>
<xs:extension base="behausung_ct">
<xs:sequence>
<xs:element name="fläche" type="xs:double"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="teich_ct">
<xs:complexContent>
<xs:extension base="behausung_ct">
<xs:sequence>
<xs:element name="wassertiefe" type="xs:double"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
This resolves all of your errors.
Upvotes: 1