Re: [xml-dev] Re: Complex or Simple content usage

Hi Jeni,

Are you sure about this?  I thought the rules for this were real simple:

complexContent extends/restricts complexTypes
simpleContent extends/restricts simpleTypes

This looks correct to me:

     <xsd:element name="HelpText">
        <xsd:complexType>
           <xsd:complexContent>
              <xsd:extension base="C-255">
                 <xsd:attribute ref="xml:lang"/>
              </xsd:extension>
           </xsd:complexContent>
        </xsd:complexType>
     </xsd:element>

"HelpText extends the complexType, C-255, with the attribute,
xml:lang."  Looking at C-255 we see that it is a simple type extended
with an id attribute.  Thus, <HelpText id=".."
xml:lang="..">...</HelpText>

Can you point me to the part of the spec that allows simpleContent to
extend a complexType?

/Roger
 
P.S. Congrats on your new book and award!



Jeni Tennison wrote:
> 
> Hi Danny,
> 
> Your question is appropriate for xmlschema-dev@w3.org. You probably
> shouldn't cross-post to xml-dev@lists.xml.org. I'm only cross-posting
> so that they know it's been answered; please post follow-ups to
> xmlschema-dev@w3.org.
> 
> > The problem seems to be around the use of simpleContent or
> > complexContent and these types:
> >
> > Here are my base definitions of the types that I use:
> >
> >     <xsd:complexType name="C-255">
> >        <xsd:simpleContent>
> >           <xsd:extension base="C-255_NoID">
> >              <xsd:attribute ref="id"/>
> >           </xsd:extension>
> >        </xsd:simpleContent>
> >     </xsd:complexType>
> >     <xsd:simpleType name="C-255_NoID">
> >        <xsd:restriction base="xsd:string">
> >           <xsd:maxLength value="255"/>
> >           <xsd:minLength value="1"/>
> >        </xsd:restriction>
> >     </xsd:simpleType>
> >
> > I then have the following:
> >
> >     <xsd:element name="HelpText">
> >        <xsd:complexType>
> >           <xsd:complexContent>
> >              <xsd:extension base="C-255">
> >                 <xsd:attribute ref="xml:lang"/>
> >              </xsd:extension>
> >           </xsd:complexContent>
> >        </xsd:complexType>
> >     </xsd:element>
> >
> > MS-XML indicates that instead of complexContent, the definition of
> > HelpText should use simpleContent. Is this correct? Is this a real
> > error or a preferred way to define this element?
> 
> Yes, it's a real error. If you did:
> 
> <xsd:element name="HelpText">
>   <xsd:complexType>
>     <xsd:simpleContent>
>       <xsd:extension base="C-255">
>         <xsd:attribute ref="xml:lang"/>
>       </xsd:extension>
>     </xsd:simpleContent>
>   </xsd:complexType>
> </xsd:element>
> 
> then it would be just fine (and would be correct -- the HelpText
> element has two attributes (which means it must be a complex type) but
> has simple content (a string).
> 
> > If MS-XML is correct, could we have made the Schema process any more
> > difficult? Why can't I use complexContent, with a type defined as a
> > complexType and simpleContent with a type defined as simpleType?
> 
> I agree that this can be confusing. XML Schema divides types into two
> kinds: complex types, which allow element content and/or attributes;
> and simple types, which don't. XML Schema then splits complex types
> (which allow attributes) into two classes: those with purely textual
> content (simple content) and those with element content (complex
> content). Diagrammatically:
> 
>                  Type
>                   /\
>                  /  \
>                 /    \
>            Simple    Complex           allows attributes or elements?
>             Type      Type
>                        /\
>                       /  \
>                      /    \
>                  Simple  Complex       allows elements in content?
>                 Content  Content
> 
> The restriction that you're running into is that you can't derive a
> complex type with complex content from one with simple content. If you
> need to extend a complex type with textual content to one that also
> allows elements, then you have to start off with a complex type that
> has complex content (allows elements in the first place) and is mixed
> (to allow the text that you want). Similarly, you can't derive a
> complex type from a simple type except to extend it by adding
> attributes. I guess that this prevents you from doing:
> 
> <xs:complexType name="price">
>   <xs:complexContent>
>     <xs:extension base="xs:decimal">
>       <xs:element name="currency" type="xs:token" />
>     </xs:extension>
>   </xs:complexContent>
> </xs:complexType>
> 
> to validate:
> 
>   <price>12.99<currency>GBP</currency></price>
> 
> but that's pretty bad XML design anyway (and I'll note that RELAX NG
> doesn't support it either).
> 
> Cheers,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>

Received on Monday, 12 August 2002 08:04:50 UTC