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

Re: Selective element based on attribute

From: Pete Cordell <petexmldev@tech-know-ware.com>
Date: Fri, 5 Oct 2007 11:41:26 +0100
Message-ID: <002b01c8073c$4a99e150$4000a8c0@Codalogic>
To: <xmlschema-dev@w3.org>, <Muthuvelan.Swaminathan@dds.net>

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 GMT

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