Simple "article" xsd

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

Simple "article" xsd

Sun Nov 28, 2004 2:15 am

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: 2100

Mon Nov 29, 2004 10:43 am

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

Wed Dec 01, 2004 12:10 am

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

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

-David

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests