Page 1 of 1

What's wrong in this schema?

Posted: Thu Dec 13, 2007 1:35 pm
by josandres
Good morning:
I'm trying to use JAXB and i have written the following schema:

<xsd:complexType name="MetaInformation"> <xsd:sequence> <xsd:element name="description" type="xsd:string" default=""/> <xsd:element name="keyword" type="xsd:string" maxOccurs="unbounded" minOccurs="0" default="" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name = "xmldisplaydefinition"> <xsd:attribute name="identifier" type="xsd:string"/> <xsd:attribute name="kindOfDisplay" type="xsd:string"/> <xsd:sequence> <xsd:element name="metaInformation" type="MetaInformation" maxOccurs="1" minOccurs="0"/> </xsd:sequence> </xsd:complexType>
when i validate my schema i receive the following error:
Invalid per cvc-complex-type.1.2.4: element {http://www.w3.org/2001/XMLSchema}:sequence not allowed here (5) in element {http://www.w3.org/2001/XMLSchema}:complexType, expecting
[{http://www.w3.org/2001/XMLSchema}:anyAt ... ibuteGroup]

Posted: Thu Dec 13, 2007 1:35 pm
by josandres
Sorry for the bad formatting

<xsd:complexType name="MetaInformation"> <xsd:sequence> <xsd:element name="description" type="xsd:string" default=""/> <xsd:element name="keyword" type="xsd:string" maxOccurs="unbounded" minOccurs="0" default="" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name = "xmldisplaydefinition"> <xsd:attribute name="identifier" type="xsd:string"/> <xsd:attribute name="kindOfDisplay" type="xsd:string"/> <xsd:sequence> <xsd:element name="metaInformation" type="MetaInformation" maxOccurs="1" minOccurs="0"/> </xsd:sequence> </xsd:complexType>

Posted: Thu Dec 13, 2007 3:29 pm
by Radu
Hi

The error message occurs because the 'xsd:sequence' element must be declared before declaring any attributes in the complex type. The correct schema should look like this :

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="MetaInformation">
<xsd:sequence>
<xsd:element name="description" type="xsd:string" default=""/>
<xsd:element name="keyword" type="xsd:string" maxOccurs="unbounded" minOccurs="0"
default=""/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="xmldisplaydefinition">
<xsd:sequence>
<xsd:element name="metaInformation" type="MetaInformation" maxOccurs="1" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="identifier" type="xsd:string"/>
<xsd:attribute name="kindOfDisplay" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
Best regards,
Radu