Choice between complextContent and complexType

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Choice between complextContent and complexType

Karl Stubsjoen
I have an element "description", who should either extend the
complexType "formInputTypes" or contain a sequence of "column"
elements.  Is this possible?

--
Karl Stubsjoen
MeetScoresOnline.com
(602) 845-0006

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Mukul Gandhi
Hi Karl,
     One way is to use the type alternative construct from XML Schema
1.1. Here's probably something we may be able to do for this use case
(this is untested),

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

     <xs:element name="description" type="xs:anyType">
           <xs:alternative test="@isExt = true()" type="EXT_formInputTypes"/>
           <xs:alternative type="SEQ_TYPE"/>
     </xs:element>

    <xs:complexType name="EXT_formInputTypes">
          <xs:complexContent>
                <xs:extension base="formInputTypes">
                      <xs:attribute name="isExt" type="xs:boolean" default="1"/>
                </xs:extension>
          </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="SEQ_TYPE">
           <xs:sequence>
                <xs:element name="column" type="COL_TYPE"/> <!-- COL_TYPE is
undefined. could be xs:string for e.g -->
           </xs:sequence>
           <xs:attribute name="isExt" type="xs:boolean"/>
    </xs:complextype>

</xs:schema>

As per this example, by default the type of "description" is
EXT_formInputTypes. But if we add an attribute isExt = 0 (false) to
"description" in the instance document, the type of "description"
would be SEQ_TYPE.

On Thu, Jun 16, 2011 at 7:07 AM, Karl Stubsjoen <[hidden email]> wrote:
> I have an element "description", who should either extend the
> complexType "formInputTypes" or contain a sequence of "column"
> elements.  Is this possible?
>
> --
> Karl Stubsjoen
> MeetScoresOnline.com
> (602) 845-0006





--
Regards,
Mukul Gandhi

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Karl Stubsjoen
Hi Mukul,
I'm trying to stick with 1.0 standards.  If there is not a 1.0
solution than I think I must define a new child element of
description.  This is what I am doing now.
Thanks,
Karl..

On Wed, Jun 15, 2011 at 8:40 PM, Mukul Gandhi <[hidden email]> wrote:

> Hi Karl,
>     One way is to use the type alternative construct from XML Schema
> 1.1. Here's probably something we may be able to do for this use case
> (this is untested),
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
>     <xs:element name="description" type="xs:anyType">
>           <xs:alternative test="@isExt = true()" type="EXT_formInputTypes"/>
>           <xs:alternative type="SEQ_TYPE"/>
>     </xs:element>
>
>    <xs:complexType name="EXT_formInputTypes">
>          <xs:complexContent>
>                <xs:extension base="formInputTypes">
>                      <xs:attribute name="isExt" type="xs:boolean" default="1"/>
>                </xs:extension>
>          </xs:complexContent>
>    </xs:complexType>
>
>    <xs:complexType name="SEQ_TYPE">
>           <xs:sequence>
>                <xs:element name="column" type="COL_TYPE"/>     <!-- COL_TYPE is
> undefined. could be xs:string for e.g -->
>           </xs:sequence>
>           <xs:attribute name="isExt" type="xs:boolean"/>
>    </xs:complextype>
>
> </xs:schema>
>
> As per this example, by default the type of "description" is
> EXT_formInputTypes. But if we add an attribute isExt = 0 (false) to
> "description" in the instance document, the type of "description"
> would be SEQ_TYPE.
>
> On Thu, Jun 16, 2011 at 7:07 AM, Karl Stubsjoen <[hidden email]> wrote:
>> I have an element "description", who should either extend the
>> complexType "formInputTypes" or contain a sequence of "column"
>> elements.  Is this possible?
>>
>> --
>> Karl Stubsjoen
>> MeetScoresOnline.com
>> (602) 845-0006
>
>
>
>
>
> --
> Regards,
> Mukul Gandhi
>



--
Karl Stubsjoen
MeetScoresOnline.com
(602) 845-0006

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Mukul Gandhi
I tried to implement the choice constraint you mentioned with XSD 1.1
type alternatives.

I'm not sure, if there's an XSD 1.0 solution for such a choice use case.

If the workaround you're suggesting suites your environment, please
feel free to use that.

On Thu, Jun 16, 2011 at 9:48 AM, Karl Stubsjoen <[hidden email]> wrote:
> Hi Mukul,
> I'm trying to stick with 1.0 standards.  If there is not a 1.0
> solution than I think I must define a new child element of
> description.  This is what I am doing now.
> Thanks,
> Karl..




--
Regards,
Mukul Gandhi

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Karl Stubsjoen
Yes, I appreciate that.  Thanks Mukul.
Karl..

On Wed, Jun 15, 2011 at 9:24 PM, Mukul Gandhi <[hidden email]> wrote:

> I tried to implement the choice constraint you mentioned with XSD 1.1
> type alternatives.
>
> I'm not sure, if there's an XSD 1.0 solution for such a choice use case.
>
> If the workaround you're suggesting suites your environment, please
> feel free to use that.
>
> On Thu, Jun 16, 2011 at 9:48 AM, Karl Stubsjoen <[hidden email]> wrote:
>> Hi Mukul,
>> I'm trying to stick with 1.0 standards.  If there is not a 1.0
>> solution than I think I must define a new child element of
>> description.  This is what I am doing now.
>> Thanks,
>> Karl..
>
>
>
>
> --
> Regards,
> Mukul Gandhi
>



--
Karl Stubsjoen
MeetScoresOnline.com
(602) 845-0006

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Michael Kay
In reply to this post by Karl Stubsjoen
On 16/06/2011 02:37, Karl Stubsjoen wrote:
> I have an element "description", who should either extend the
> complexType "formInputTypes" or contain a sequence of "column"
> elements.  Is this possible?
>
Can you modify formInputTypes so that its content model is extracted
into a named model group? If you can, then it's easy to define a new
type using xs:choice that has this model group as one of its branches.

(I wish it were possible to refer to the content model of a complex type
without having to do this, but unfortunately it isn't)

Michael Kay
Saxonica

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Mukul Gandhi
In reply to this post by Mukul Gandhi
On Thu, Jun 16, 2011 at 9:10 AM, Mukul Gandhi <[hidden email]> wrote:
>    <xs:complexType name="EXT_formInputTypes">
>          <xs:complexContent>
>                <xs:extension base="formInputTypes">
>                      <xs:attribute name="isExt" type="xs:boolean" default="1"/>
>                </xs:extension>
>          </xs:complexContent>
>    </xs:complexType>

There's a slight correction I would suggest for the above schema
fragment I wrote.

default="1" on xs:attribute won't work I think, since the
xs:alternative has to know the attribute (and it's value) from the
instance document, and then it'll select the type if the corresponding
XPath predicate is true.

Therefore for both the xs:alternative cases I suggested, the attribute
"isExt" should be present in the instance document (with values 1/true
or 0/false) for the example I suggested to work correctly.

I hope this is correct.




--
Regards,
Mukul Gandhi

Reply | Threaded
Open this post in threaded view
|

Re: Choice between complextContent and complexType

Karl Stubsjoen
Thanks for the followup on this Mukul.

On Thu, Jun 16, 2011 at 1:30 AM, Mukul Gandhi <[hidden email]> wrote:

> On Thu, Jun 16, 2011 at 9:10 AM, Mukul Gandhi <[hidden email]> wrote:
>>    <xs:complexType name="EXT_formInputTypes">
>>          <xs:complexContent>
>>                <xs:extension base="formInputTypes">
>>                      <xs:attribute name="isExt" type="xs:boolean" default="1"/>
>>                </xs:extension>
>>          </xs:complexContent>
>>    </xs:complexType>
>
> There's a slight correction I would suggest for the above schema
> fragment I wrote.
>
> default="1" on xs:attribute won't work I think, since the
> xs:alternative has to know the attribute (and it's value) from the
> instance document, and then it'll select the type if the corresponding
> XPath predicate is true.
>
> Therefore for both the xs:alternative cases I suggested, the attribute
> "isExt" should be present in the instance document (with values 1/true
> or 0/false) for the example I suggested to work correctly.
>
> I hope this is correct.
>
>
>
>
> --
> Regards,
> Mukul Gandhi
>



--
Karl Stubsjoen
MeetScoresOnline.com
(602) 845-0006