Jump to content

How to set restriction in a complexType?


Recommended Posts

Hi to all!I've a question to ask to you.If i have a simple type, i know how to set any restriction, like this:

....<xs:element name="age" type="integer"><xs:simpleType>  <xs:restriction base="xs:integer">   <xs:minInclusive value="3"/>   <xs:maxInclusive value="10"/>  </xs:restriction></xs:simpleType></xs:element>....

So i can only put a integer number included among [3,10].if i want to do this in a complexType like here

...<xs:element name="person"><xs:complexType><xs:sequence>  <xs:element name="age" type="xs:integer">...</xs:sequence></xs:complexType></xs:element>....

it should be something like this

...<person><age>99</age></person>...

but if i want to set limits to integer value age?

Link to post
Share on other sites

You need to define your own simple type, and then set THAT type as the type of the element(s) you want it on - in this case, the "age" element.So for example:

<xs:element name="person"><xs:complexType><xs:sequence>  <xs:element name="age" type="childAge">...</xs:sequence></xs:complexType></xs:element><xs:simpleType name="childAge">  <xs:restriction base="xs:integer">   <xs:minInclusive value="3"/>   <xs:maxInclusive value="10"/>  </xs:restriction></xs:simpleType>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...