Re: defining the complex type of an element depending on the value of an attribute

XML Schema 1.0 does not permit this to be specified.

It has been requested by several people as a possible feature for XML
Schema 2.x but the W3C XML Schema WG hasn't published their thoughts on
priorities for 2.x as of now.

There are technologies, such as Schematron, which could be used as an
augmentation to validation and could express this.

In Schema 1.0, there is one special attribute, called xsi:type which can be
used for this, but then the value of that attribute must be the actual type
name.

Bob

Bob Schloss
manager, XML/XSL Transformational Systems - Extensible Technologies
IBM Thomas J. Watson Research Center
Yorktown Heights, New York, USA





                                                                                                                                      
                      Ernesto Wandeler                                                                                                
                      <ernesto@wandeler        To:       xmlschema-dev@w3.org                                                         
                      .ch>                     cc:                                                                                    
                      Sent by:                 Subject:  defining the complex type of an element depending on the value of  an        
                      xmlschema-dev-req         attribute                                                                             
                      uest@w3.org                                                                                                     
                                                                                                                                      
                                                                                                                                      
                      12/02/2002 01:23                                                                                                
                      PM                                                                                                              
                                                                                                                                      
                                                                                                                                      




Hi

i am currently defining an XML Schema for a programming language which
is represented in XML and which was already used for some time without
any DTD or XML Schema.

now i would like to know whether it is possible to define the
complexType of an element depending on the value of an attribute of the
element?

for example i have an element named <Expr> with an attribute named
"kind" and if "kind" equals "UnaryOp" then it must contain one <Op>
element and one <Expr> element. but if "kind" equals "BinaryOp" then it
must contain one <Expr> element followed by any number of <Op> and
<Expr> comibinations.

the XML could look for example like this:

<Expr kind="BinOpSeq">
             <Expr kind="UnaryOp">
                         <Op name="dom"/>
                         <Expr kind="Var" name="a"/>
             </Expr>
             <Op name="!="/>
             <Expr kind="Set"/>
             <Op name="or"/>
             <Expr kind="UnaryOp">
                         <Op name="dom"/>
                         <Expr kind="Var" name="s"/>
             </Expr>
             <Op name="!="/>
             <Expr kind="Set"/>
</Expr>

i think i could use a number of complexTypes inside a choice element but
then how could i link the choice to the attribute value of the parent
element?

thank you very much for any help!

cheers
ernesto



--
----------------------------------------------------------------------
Ernesto Wandeler

Department of Electrical Engineering and Computer Science
University of California at Berkeley
545M Cory Hall
Berkeley, CA 94720-1770
USA

Work:   +1 510 642 6873
Home:   +1 510 898 1565
Mobile: +41 76 349 4972
E-Mail: ernesto@wandeler.ch
----------------------------------------------------------------------

Received on Monday, 2 December 2002 15:31:51 UTC