Search code examples
xmldatexsdattributesrestriction

Compile error with a "restriction date" XSD


Im actually stuck at a homework with xsd attribute date, where i want to set minInclusive and maxInclusive restriction. Here is my code (My problem is in front of the : <--------) :

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema%22%3E
   <xsd:element name="cdtheque">
     <xsd:complexType> <xsd:sequence minOccurs="0">
        <xsd:element name="cd">
          <xsd:complexType>
            <xsd:all>
               <xsd:element name="titre" type="xsd:string"/>
               <xsd:element name="style" type="xsd:string"/>
               <xsd:element name="artiste" type="xsd:string"/>
             </xsd:all>
           </xsd:complexType>
         </xsd:element>
       </xsd:sequence>
        <xsd:attribute type="xsd:date" name="date">   <--------
          <xsd:simpleType>
          <xsd:restriction base="xsd:date">  
            <xsd:minInclusive value="1990-01-01"/>
            <xsd:maxInclusive value="2030-01-01"/>
          </xsd:restriction>
        </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute type="xsd:string" name="proprietaire"/>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>

And I get this fail :

xmllint --noout --schema ex3schema.xsd ex3.xml
ex3schema.xsd:15: element restriction: Schemas parser error : 
Element '{http://www.w3.org/2001/XMLSchema%7Dattribute': 
The content is not valid. Expected is (annotation?, simpleType?).
WXS schema ex3schema.xsd failed to compile

I'm beginner, but I looked on many internet websites since few days now, I checked again and again the Syntax on W3S. Still I dont see what's wrong with my code, maybe one of you could find this out ?

Thanks for your help.


Solution

  • Your xsd:attribute element has both a type attribute and an xsd:simpleType child. You can't have both.

    Not a very good error message. When you get a poor error message it can be worth trying a different schema processor.

    Xerces says:

    Attribute 'date' has both a 'type' attribute and an anonymous 'simpleType' child. Only one of these is allowed for an attribute.

    Saxon says:

    Error at xsd:attribute on line 14 column 56 of test.xsd: A <simpleType> element must not appear as a child of an <xsd:attribute> with a @type attribute

    I think that with either of these messages, you wouldn't be asking the question here.