W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2007

Newbie question. It is posible do complex type content dependent of a attribute value without xsi:type

From: Jose Luis Zabalza <jlz.3008@gmail.com>
Date: Fri, 8 Jun 2007 09:07:53 +0200
Message-ID: <854f4a0c0706080007l624a8512y7bed3f8d3898c87@mail.gmail.com>
To: xmlschema-dev@w3.org

Hello everybody.

It is posible do complex type content dependent of a attribute value
without xsi:type?

Next, is a example. TYPE content depend of class attribute values.

The next schema have two error.

First, VINIT element are diferent type on schema and I get one error
form  Schema validator.

After, content TYPE element are "unbounded" to class attribute, so, is
valid write a "bool" class atribute with a enum content.

Thanks in avance.


<!-- ==================FILE================================== -->
<?xml version="1.0" encoding="iso-8859-1" ?>
<DATATYPES
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation='datatypes.xsd'>

 <SYMBOLS>
   <TYPE id="first" class="bool">
     <VINIT>true</VINIT>
     <TRUE>this is true</TRUE>
     <FALSE>this is false</FALSE>
   </TYPE>

   <TYPE id="second" class="string">
     <VINIT>this is a string</VINIT>
     <MAXLEN>100</MAXLEN>
   </TYPE>

   <TYPE id="third" class="enum">
     <VINIT>1</VINIT>
     <OPTIONS>
       <OPTION value="1">first option</OPTION>
       <OPTION value="2">second option</OPTION>
       <OPTION value="3">third option</OPTION>
     </OPTIONS>
   </TYPE>


<!-- this is a error but good for schema  -->
   <TYPE id="fourth" class="bool">
     <VINIT>1</VINIT>
     <OPTIONS>
       <OPTION value="1">first option</OPTION>
       <OPTION value="2">second option</OPTION>
       <OPTION value="3">third option</OPTION>
     </OPTIONS>
   </TYPE>
 </SYMBOLS>

<!-- ..... anothers elements ... -->

</DATATYPES>


<!-- ============= SCHEMA ============ -->

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">


 <xsd:group name="groupClassString">
   <xsd:sequence>
     <xsd:element name="VINIT"  type="xsd:string" />
     <xsd:element name="MAXLEN"    type="xsd:unsignedInt" minOccurs="0"/>
   </xsd:sequence>
 </xsd:group>


 <xsd:group name="groupClassBool">
   <xsd:sequence>
     <xsd:element name="VINIT"  type="xsd:boolean" />
     <xsd:element name="TRUE"   type="xsd:string"/>
     <xsd:element name="FALSE"  type="xsd:string"/>
   </xsd:sequence>
 </xsd:group>


 <xsd:group name="groupClassEnum">
   <xsd:sequence>
     <xsd:element name="VINIT"  type="xsd:unsignedInt" />
     <xsd:element name="OPTIONS"  >
       <xsd:complexType>
         <xsd:sequence>
           <xsd:element name="OPTION" maxOccurs="unbounded">
             <xsd:complexType>
               <xsd:simpleContent>
                 <xsd:extension base="xsd:string">
                   <xsd:attribute name="value" type="xsd:unsignedInt"
use="required"/>
                 </xsd:extension>
               </xsd:simpleContent>
             </xsd:complexType>
           </xsd:element>
         </xsd:sequence>
       </xsd:complexType>
     </xsd:element>
   </xsd:sequence>
 </xsd:group>

 <xsd:complexType name="ClassSymbol">

   <xsd:choice >
     <xsd:group ref="groupClassString"/>
     <xsd:group ref="groupClassBool"/>
     <xsd:group ref="groupClassEnum"/>
   </xsd:choice>


   <xsd:attribute name="id" use="required" type="xsd:string"/>
   <xsd:attribute name="class" use="required">
     <xsd:simpleType>
       <xsd:restriction base="xsd:string">
         <xsd:enumeration value="string"/>
         <xsd:enumeration value="bool"/>
         <xsd:enumeration value="enum"/>
       </xsd:restriction>
     </xsd:simpleType>
   </xsd:attribute>
 </xsd:complexType>



 <xsd:element name="DATATYPES">
   <xsd:complexType>
     <xsd:sequence>
       <xsd:element name="SYMBOLS">
         <xsd:complexType >
           <xsd:sequence>
             <xsd:element name="TYPE" minOccurs="0" maxOccurs="unbounded"
                      type="ClassSymbol" />
           </xsd:sequence>
         </xsd:complexType>
       </xsd:element>
<!-- ....... Others elements ....... -->
     </xsd:sequence>
   </xsd:complexType>
 </xsd:element>


</xsd:schema>



-- 
Josť Luis Zabalza
jlz.3008  a t  gmail.com
Linux Counter 172551
Received on Friday, 8 June 2007 14:16:01 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:59 GMT