XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Here's a hack to avoid the dreaded "Unique ParticleAttribution" error

But Roger, why not

<xs:sequence>
  <xs:element name="Title" type="xs:string"/>
  <xs:choice>
    <xs:element name="ISBN" type="xs:string"/>
    <xs:element name="Edition" type="xs:string"/>
  </xs:choice>
</xs:sequence>

Greetings, Frank


Am 21.01.22 um 15:44 schrieb Roger L Costello:
Hi Folks,

This XML Schema choice:

<xs:choice>
    <xs:sequence>
        <xs:element name="Title" type="xs:string"/>
        <xs:element name="ISBN" type="xs:string"/>
    </xs:sequence>
    <xs:sequence>
        <xs:element name="Title" type="xs:string"/>
        <xs:element name="Edition" type="xs:string"/>
    </xs:sequence>
</xs:choice>

results in this error: 

	Title and Title violate "Unique Particle Attribution".
	During validation against this schema, ambiguity 
	would be created for those two particles.

The branches of a choice cannot start with the same element name.

Suppose, for whatever reason, you need the choices to start with the Title element, what to do?

Here's a hack: Create a base complexType and for each branch of the choice create a subtype:

<xs:complexType name="Publication" abstract="true" />

<xs:complexType name="BookPublication">
    <xs:complexContent>
        <xs:extension base="Publication">
            <xs:sequence>
                <xs:element name="Title" type="xs:string"/>
                <xs:element name="ISBN" type="xs:string"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="MagazinePublication">
    <xs:complexContent>
        <xs:extension base="Publication">
            <xs:sequence>
                <xs:element name="Title" type="xs:string"/>
                <xs:element name="Edition" type="xs:string"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

Declare an element with the base type, Publication, as its type:

<xs:element name="Item" type="Publication"/>

In an XML instance document, if you want the <Item> element to hold book data (Title, ISBN), do this:

<Item xsi:type="BookPublication">
    <Title>...</Title>
    <ISBN>...</ISBN>
</Item>

If you want the <Item> element to hold magazine data (Title, Edition), do this:

<Item xsi:type="MagazinePublication">
    <Title>...</Title>
    <Edition>...</Edition>
</Item>

TaDa!

/Roger

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS