Re: trouble with content models

It seems XML Schema 1.1 assertions can make few of the schema design
tasks simpler for such a scenario.

Following is a sample schema written using this idiom:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://po-trans" xmlns:po="http://po-trans"
elementFormDefault="qualified">

    <element name="PO_TRANS" type="po:POSTransactionLineItemDiscount" />
 
    <complexType name="POSTransactionLineItemDiscount">
        <sequence>
            <element name="discountAmount" type="decimal" minOccurs="0"/>
            <element name="discountAmountReasonCode" type="string"
minOccurs="0"/>
     <element name="discountPercentage" type="decimal" minOccurs="0"/>
            <element name="discountPercentageReasonCode" type="string"
minOccurs="0"/>
        </sequence>
        <assert test="(discountAmount, discountAmountReasonCode) or
(discountPercentage, discountPercentageReasonCode)
                             or (discountAmount,
discountAmountReasonCode, discountPercentage,
discountPercentageReasonCode)"
        xpathDefaultNamespace="##targetNamespace" />
     </complexType>

</schema>

This would require an XML instance document like following:

<PO_TRANS xmlns="http://po-trans">
    <discountAmount>11</discountAmount>
    <discountAmountReasonCode>xx</discountAmountReasonCode>
</PO_TRANS>

On Wed, Dec 15, 2010 at 9:13 AM, Andy Davidson <andy_davidson@apple.com> wrote:
> Hi
> its been a while since I worked with XML Schema. I am not sure I am posting
> to the correct group. I want to define a content model (a | b | (a &b))
> Any idea how I can do this?
> I have tried various version of the following I keep getting the following
> validation error from Eclipse on my POSTransactionLineItemDiscount type
> cos-nonambig: discountAmount and discountAmount (or elements from their
> substitution group) violate "Unique Particle Attribution". During validation
> against this schema, ambiguity would be created for those two particles.
> <group name="POSTransactionLineItemDiscountByAmount"
> id="POSTransactionLineItemDiscountByAmount">
>   <sequence>
>      <element name="discountAmount" type="decimal" minOccurs="0"/>
>      <element name="discountAmountReasonCode" type="string" minOccurs="0"/>
>   </sequence>
> </group>
> <group name="POSTransactionLineItemDiscountByPercent">
>   <sequence>
>   <element name="discountPercentage" type="decimal" minOccurs="0"/>
>         <element name="discountPercentageReasonCode" type="string"
> minOccurs="0"/>
>   </sequence>
> </group>
> <group name="POSTransactionLineItemDiscountByAmountAndPercent">
>   <sequence>
>    <element name="discountAmount" type="decimal" minOccurs="0"/>
>         <element name="discountAmountReasonCode" type="string"
> minOccurs="0"/>
>   <element name="discountPercentage" type="decimal" minOccurs="0"/>
>         <element name="discountPercentageReasonCode" type="string"
> minOccurs="0"/>
>   </sequence>
> </group>
> <complexType name="POSTransactionLineItemDiscount">
>   <sequence>
>         <choice>
>      <group ref="pos:POSTransactionLineItemDiscountByAmountAndPercent" />
>         <group ref="pos:POSTransactionLineItemDiscountByAmount" />
>         <group ref="pos:POSTransactionLineItemDiscountByPercent" />
>         </choice>
>  </sequence>
> </complexType>
> I guess I could define a complex base type, and have three extensions to
> cover the 3 possible content valid content models. How ever this would
> require me to rework some legacy java applications
> thanks
> Andy




-- 
Regards,
Mukul Gandhi

Received on Wednesday, 15 December 2010 11:19:44 UTC