LeeTee
LeeTee

Reputation: 6601

simple XML Schema - XSD

I have the following xsd file which is throwing "invalid schema" error. I have done many complex schemas before but cannot seem to figure out what is wrong with this one, which should be very straight forward. I know I need something after

<xsd:element name="ebay">

but what?

XML:
<ebay><userID></userID></ebay>


Schema:
    <?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="ebay">

<xsd:element name="userID">
   <xsd:simpleType>
     <xsd:restriction base="xsd:string">
       <xsd:minLength value="1"/>
       <xsd:maxLength value="255"/>
       <xsd:whiteSpace value="collapse"/> 
     </xsd:restriction>
   </xsd:simpleType>
 </xsd:element>

</xsd:element>
</xsd:schema>

Upvotes: 0

Views: 765

Answers (2)

tom redfern
tom redfern

Reputation: 31780

Try this schema:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="ebay">
    <xs:complexType>
      <xs:sequence>
        <xsd:element name="userID">
          <xsd:simpleType>
            <xsd:restriction base="xsd:string">
              <xsd:minLength value="1"/>
              <xsd:maxLength value="255"/>
              <xsd:whiteSpace value="collapse"/> 
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
      </xs:sequence>
    </xs:complexType>
  </xsd:element>
</xsd:schema>

Upvotes: 0

DanBrum
DanBrum

Reputation: 439

You need to define the namespace xs: to "http://www.w3.org/2001/XMLSchema", you're using two namespaces but have only defined xsd. You should really just use one or the other. Also I don't believe you can use minInclusive value or maxInclusiveValue on a string.

Upvotes: 1

Related Questions