Re: How to define a complexType so that derived types can have simple content or complex content?

Mukul Gandhi <[email protected]>
Newsgroups gmane.text.xml.schema.devel
Message-ID <CABuuzNNYcqeCFEdpGdNO0JCestC2-gFpXRcd5v+dgg5Q8GEucQ@mail.gmail.com>
It seems I got this XSD fragment wrong ("alternative" is child of
"element" and not "complexType"). Wrote this quickly without testing
and apologies for confusion.

The solution you proposed may be the way forward, or we should
continue discussion along lines what Mike wrote.

On Thu, Nov 3, 2011 at 7:28 AM, Mukul Gandhi <[email protected]> wrote:
> Hi Roger,
>    It seems use cases like this become little more natural to be
> solved (i.e better semantic modeling of the problem domain XSD type
> system) with XSD 1.1. Here's a proposed XSD 1.1 answer for this use
> case using the CTA construct,
>
> <xs:element name="title" type="property"/>
>
> <xs:element name="author" type="property"/>
>
> <xs:complexType name="property" type="xs:anyType">
>      <xs:alternative test="name() = 'title'">
>          <xs:simpleType>
>              <xs:restriction base="xs:string">
>                  <xs:maxLength value="100" />
>              </xs:restriction>
>         </xs:simpleType>
>     </xs:alternative>
>     <xs:alternative test="name() = 'author'">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element ref="Person" />
>             </xs:sequence>
>         </xs:complexType>
>     </xs:alternative>
>     <xs:alternative type="xs:error"/>
> </xs:complexType>
>
> On Thu, Nov 3, 2011 at 1:35 AM, Costello, Roger L. <[email protected]> wrote:
>> Hi Folks,
>>
>> I would like to associate this title element with a complexType named property:
>>
>> <title>The Implementation of Functional Programming Languages</title>
>>
>> Notice that this "property element" has simple content.
>>
>> I would like to associate this author element with the same property complexType:
>>
>>    <author>
>>        <Person>
>>            <name>Simon L. Peyton Jones</name>
>>        </Person>
>>    </author>
>>
>> Observe that this property element has complex content.
>>
>> Thus, there are property elements with simple content and property elements with complex content.
>>
>> How do I define a property complexType such that it can be restricted to simpleContent and extended to complexContent?
>>
>> The following works, but I am not happy with it because it uses mixed="true" which I do not want. The <author> element has mixed content. Is there a way to implement this without requiring some property elements to have mixed content?   /Roger
>>
>>    <xs:complexType name="property" abstract="true" mixed="true" />
>>
>>    <xs:element name="title" type="titleType" />
>>
>>    <xs:complexType name="titleType">
>>        <xs:simpleContent>
>>            <xs:restriction base="property">
>>                <xs:simpleType>
>>                    <xs:restriction base="xs:string">
>>                        <xs:maxLength value="100" />
>>                    </xs:restriction>
>>                </xs:simpleType>
>>            </xs:restriction>
>>        </xs:simpleContent>
>>    </xs:complexType>
>>
>>    <xs:element name="author" type="authorType" />
>>
>>    <xs:complexType name="authorType" mixed="true">
>>        <xs:complexContent>
>>            <xs:extension base="property">
>>                <xs:sequence>
>>                    <xs:element ref="Person" />
>>                </xs:sequence>
>>            </xs:extension>
>>        </xs:complexContent>
>>    </xs:complexType>





-- 
Regards,
Mukul Gandhi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.