Re: Selective element based on attribute

In addition to Michael Kay's reply, you might want to define your attr 
attribute to be an xs:list schema type, which causes the attribute value to 
be a space separated list (e.g. attr="add del chg").  Using a more 
conventional list definition may mean that the various tools can give you 
better service.

The schema segment for that would look something like:

    <xs:attribute name="attr">
        <xs:simpleType>
            <xs:list>
                <xs:simpleType>
                    <xs:restriction base="xs:token">
                        <xs:enumeration value="add"/>
                        <xs:enumeration value="del"/>
                        <xs:enumeration value="chg"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:list>
        </xs:simpleType>
    </xs:attribute>

This doesn't prevent you having an instance looking like attr="add add add". 
I'm not sure there is a convenient way to prevent that though and still be 
part of an xs:list.

HTH,

Pete.
=============================================
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
 http://www.codalogic.com/lmx/
=============================================

----- Original Message ----- 
From: <Muthuvelan.Swaminathan@dds.net>
To: <xmlschema-dev@w3.org>
Sent: Thursday, October 04, 2007 8:32 PM
Subject: Selective element based on attribute


> Hi  there,
>
> How can I define an xsd for the following scenario?
>
> <parenttag attr="add | del | chg">
>     <childtag1>chidvalue1</childtag1>
>     <childtag2>chidvalue2</childtag2>
>     <childtag3>chidvalue3</childtag3>
> </parenttag>
>
> Is it possible to create an xsd where childtag3 will have a value null if
> the parenttag  attr equals add else a nonnull-String when the parenttag
> attr is del/chg?
>
> Thanks
> Muthu 

Received on Friday, 5 October 2007 10:41:46 UTC