W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2003

Re: xsd:choice between simpleContent and an element

From: Jeremy Vander Kam <Jeremy.C.VanderKam@nasa.gov>
Date: Fri, 05 Dec 2003 14:25:39 -0500
Message-Id: <5.2.1.1.2.20031205141904.00b9b8d8@mail.arc.nasa.gov>
To: "Paul Kiel" <paul@hr-xml.org>, <xmlschema-dev@w3.org>

Paul,

Yeah - not exactly what I wanted. What I ended up doing was:

         <xsd:complexType name="DistributedDouble" mixed="true">
                 <xsd:complexContent>
                         <xsd:extension base="BaseDouble">
                                 <xsd:sequence minOccurs="0" maxOccurs="1">
                                         <xsd:element name="Distribution" 
type="BaseDistribution"/>
                                 </xsd:sequence>
                         </xsd:extension>
                 </xsd:complexContent>
         </xsd:complexType>
         <xsd:complexType name="BaseDouble" mixed="false">
                 <xsd:simpleContent>
                         <xsd:extension base="xsd:double">
                                 <xsd:attribute name="type" use="optional">
                                         <xsd:simpleType>
                                                 <xsd:restriction 
base="xsd:string">
                                                         <xsd:enumeration 
value="double"/>
                                                 </xsd:restriction>
                                         </xsd:simpleType>
                                 </xsd:attribute>
                                 <xsd:attributeGroup ref="SimpleAttributes"/>
                         </xsd:extension>
                 </xsd:simpleContent>
         </xsd:complexType>

and

<xsd:complexType name="BaseDistribution">
         <xsd:sequence>
             <xsd:element name="LowerBound" type="AEEDouble" minOccurs="0"/>
             <xsd:element name="Mean" type="AEEDouble"/>
             <xsd:element name="Median" type="AEEDouble" minOccurs="0"/>
             <xsd:element name="StandardDeviation" type="AEEDouble" 
minOccurs="0"/>
             <xsd:element name="UpperBound" type="AEEDouble" minOccurs="0"/>
         </xsd:sequence>
     </xsd:complexType>

I then have derived extensions form "BaseDistribution" that I can control 
by using the xsi:type attribute in teh <Distribution/> element.

The things that this doesn't do that I want is that when an item is defined 
as type="DistributedDouble" and it does NOT have the Distributed element as 
a child and has text instead, I can't control that that text is in face of 
type xsd:double. I also can't seem to control that if the text exists, then 
the element MUST have a @type attribute.. oh well. This is pretty close though.

One thing is that this works great with xerces java 2.2 sax and dom 
parsers, but XMLSpy bails on it. XMLSpy insists that an element of type 
"DistributedDouble" MUST NOT have a text child. I thought (and xerces does 
too) that the mixed="true" attribute of the DistributedDouble type would 
allow that...

Thanks for your input!

- Jeremy

At 02:06 PM 12/5/2003, Paul Kiel wrote:
>The only way I can see you doing this is:
>
>option 1) declaring "Distribution" as an ANY data type (but you lose
>enforcement of data types)
>
>or option 2) you need to define two elements and keep the choice (but the
>two elements can't both be named the same thing).
>
>But I suspect neither of these is exactly what you want.
>
>You may also try something like using "xsi:type" in the instance, but I have
>no experience with that.
>
>Cheers,
>Paul
>
>W. Paul Kiel
>HR-XML Consortium
>
>----- Original Message -----
>From: "Jeremy Vander Kam (ARC)" <Jeremy.C.VanderKam@nasa.gov>
>To: <xmlschema-dev@w3.org>
>Sent: Monday, December 01, 2003 1:27 PM
>Subject: xsd:choice between simpleContent and an element
>
>
> >
> > Hi all,
> >
> > I would like to do something like this:
> >
> > <xsd:complexType name="MyType">
> >   <xsd:choice>
> >    <xsd:element name="Distribution" type="DistType"/>
> >    <xsd:simpleContent>
> >      <xsd:extension base="xsd:double">
> >        <xsd:attribute name="type" use="required">
> >            <xsd:simpleType>
> >              <xsd:restriction base="xsd:string">
> >                <xsd:enumeration value="double"/>
> >              </xsd:restriction>
> >            </xsd:simpleType>
> >          </xsd:attribute>
> >      </xsd:extension>
> >    </xsd:simpleContent>
> >   </xsd:choice>
> > </xsd:complexType>
> >
> > So I have the option of defining an element by either a set of attributes
> > and simple content OR by a child element.... Is this possible? If so, how?
> > I would like to be able to specify something like:
> >
> > <xsd:element name="Variable" type="MyType/>
> >
> >   such that the resulting XML could be either:
> >
> > <Variable>42.1</Variable>
> >
> > or
> >
> > <Variable>
> >    <Distribution/>
> > </Variable>
> >
> > But NOT mixed content such as:
> >
> > <Variable>
> >    42.1<Distribution/>
> > </Variable>
> >
> > So I guess the "gotcha" is that I want to control the type of the content
> > when it is simpleContent - making it xsd:double in this example.
> >
> > Thanks!
> >
> >
> > ----------
> > Jeremy Vander Kam
> > Aerospace Engineer
> > Systems Analysis Branch
> > NASA Ames Research Center
> > Jeremy.C.VanderKam@nasa.gov
> > 513 871 7425
> >
> >
> >

----------
Jeremy Vander Kam
Aerospace Engineer
NASA Ames Research Center
Jeremy.C.VanderKam@nasa.gov
(513) 871-7425 
Received on Friday, 5 December 2003 14:25:21 GMT

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