How to make restrictions on XML Schema Complex type?

Posted by chobo2 on Stack Overflow See other posts from Stack Overflow or by chobo2
Published on 2010-05-02T23:55:39Z Indexed on 2010/05/03 0:07 UTC
Read the original article Hit count: 154

Filed under:
|

Hi

I am reading the tutorials on w3cschools ( http://www.w3schools.com/schema/schema_complex.asp ) but they don't seem to mention how you could add restrictions on complex types.

Like for instance I have this schema.

<xs:element name="employee">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

now I want to make sure the firstname is no more then 10 characters long. How do I do this?

I tried to put in the simple type for the firstname but it says I can't do that since I am using a complex type.

So how do I put restrictions like that on the file so the people who I give the schema to don't try to make the firstname 100 characters.

© Stack Overflow or respective owner

Related posts about xml-schema

Related posts about Xml