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

Re: trouble with content models

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Wed, 15 Dec 2010 16:48:56 +0530
Message-ID: <AANLkTinanqnaKVg6k7ia7M6tUo1GEFZvCJPwTPO+Cc4T@mail.gmail.com>
To: Andy Davidson <andy_davidson@apple.com>
Cc: xmlschema-dev@w3.org
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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:18 UTC