Jump to content

Help with element with just one attribute

Recommended Posts

Hello,I need a XSD schema to validate an XML. It has to define just one element (and the root) call "EL_ONE" which has no elements and its text can be a number between 0 and 7. The lement must have an attribute call 'Id' (a string).I have this schema but it's not correct:

<xs:schema > <xs:element name="ELEMENTS">	<xs:complexType> 		  <xs:sequence>				  <xs:element ref="EL_ONE" />				  </xs:sequence>					</xs:complexType></xs:element>	 <xs:element name="EL_ONE"" type="ZERO_SEVEN_Type"/>		<xs:complexType name="ZERO_ONE_Type">  <xs:simpleContent>	<xs:extension  base="xs:integer">	<xs:attribute name="id" type="xs:string" />   <xs:restriction base="xs:integer">		  <xs:minInclusive value="0"/>		  <xs:maxInclusive value="1"/>   </xs:restriction>   </xs:extension > </xs:simpleContent></xs:complexType> 	</xs:schema>

Link to post
Share on other sites
  • 2 weeks later...

define a simpletype at first and use this simpletype to extend the complextype you need<xs:schema ><xs:element name="ELEMENTS"> <xs:complexType> <xs:sequence> <xs:element ref="EL_ONE" /> </xs:sequence> </xs:complexType></xs:element> <xs:simpleType name="ZERO_ONE_Type"> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="7"/> </xs:restriction></xs:simpleType><xs:element name="EL_ONE"> <xs:complexType> <xs:simpleContent> <xs:extension base="ZERO_ONE_Type"> <xs:attribute name="id" type="xs:string" /> </xs:extension > </xs:simpleContent> </xs:complexType></xs:element> </xs:schema>hope can help you

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.

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.

  • Create New...