What's wrong in this schema?

This should cover W3C XML Schema, Relax NG and DTD related problems.
josandres
Posts: 2
Joined: Thu Dec 13, 2007 1:30 pm

What's wrong in this schema?

Post 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]
josandres
Posts: 2
Joined: Thu Dec 13, 2007 1:30 pm

Post 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>
Radu
Posts: 9047
Joined: Fri Jul 09, 2004 5:18 pm

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply