Simple "article" xsd

This should cover W3C XML Schema, Relax NG and DTD related problems.
Guest

Simple "article" xsd

Post by Guest »

Hello -

I am trying to uild a simple xsd for articles. The article has a title, author, creation, publication, and modification dat as well as some other elements. One of the elements is the "publication". The following doesn´t seem to be valid:

<?xml version="1.0" encoding="UTF-8"?>
<?altova_sps C:\Program Files\Altova\XMLSpy2005\Examples\Conditional.sps?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Article">
<xs:complexType>
<xs:sequence>
<xs:element name="ArticleTitle" type="xs:string"/>
<xs:element name="ArticleAuthor" type="xs:string"/>
<xs:element name="ArticlePublication" type="xs:string" default="The Leader"/>
<xs:element name="ArticleEditionNo" type="xs:integer"/>
<xs:element name="ArticleCreationDate" type="xs:date" default="2005-01-01"/>
<xs:element name="ArticleModificationDate" type="xs:date" default="2005-01-01"/>
<xs:element name="ArticlePublicationDate" type="xs:date" default="2005-01-01"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="The Leader"/>
<xs:enumeration value="Levante Golf"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>

Why?

Best regards,

Neil.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Neil,

You cannot have both a complex type and a simple type for an element. If you remove the following

Code: Select all


<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="The Leader"/>
<xs:enumeration value="Levante Golf"/>
</xs:restriction>
</xs:simpleType>
then the remaining schema will be valid:

Code: Select all


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Article">
<xs:complexType>
<xs:sequence>
<xs:element name="ArticleTitle" type="xs:string"/>
<xs:element name="ArticleAuthor" type="xs:string"/>
<xs:element name="ArticlePublication" type="xs:string" default="The Leader"/>
<xs:element name="ArticleEditionNo" type="xs:integer"/>
<xs:element name="ArticleCreationDate" type="xs:date" default="2005-01-01"/>
<xs:element name="ArticleModificationDate" type="xs:date" default="2005-01-01"/>
<xs:element name="ArticlePublicationDate" type="xs:date" default="2005-01-01"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Best Regards,
George
dnedrow
Posts: 60
Joined: Wed Jan 28, 2004 10:51 pm

Post by dnedrow »

Also, just because I can't resist asking...

Why don't you simply use the DocBook Article schema?

-David
Post Reply