- From: Frank Steimke <f-steimke@b...>
- To: xml-dev@l...
- Date: Sun, 23 Jan 2022 10:53:40 +0100
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@l...
subscribe: xml-dev-subscribe@l...
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]
|