W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2005

The same element in one content model with different type

From: Michael Stolp <Michael.Stolp@stud.tu-ilmenau.de>
Date: Thu, 03 Nov 2005 12:44:21 +0100
To: xmlschema-dev@w3.org
Message-ID: <op.sznxj7yst45kwc@faet>

Hello list.

I have a problem to write a schema for the following:

<Bar id="Bar2" original_id="B5" zIndex="1">
	<Point posRef="pos2" id="Bar2.pt1" role="start"/>
	<Point posRef="pos3" id="Bar2.pt2" role="end"/>
	<Point posRef="pos5" id="Bar2.pt3" role="middle1"/>
</Bar>

A Bar _must_ have start and end Point and _can_ have 0 or more middle
Points.
But how to define this in the schema?
I did try the following:

<xs:element name="Point" type="point_type"/>

<xs:complexType name="point_type">
	<xs:attribute name="id" type="xs:NMTOKEN"/>
	<xs:attribute name="posRef" type="xs:NMTOKEN"/>
	<xs:attribute name="role" type="xs:NMTOKEN"/>
</xs:complexType>

<xs:element name="Bar">
	<xs:complexType>
		<xs:sequence>
			<xs:element name="Point" minOccurs="2" maxOccurs="2">
				<xs:complexType>
					<xs:complexContent>
						<xs:restriction base="point_type">
							<xs:attribute name="id" type="xs:NMTOKEN"/>
							<xs:attribute name="posRef" type="xs:NMTOKEN"/>
							<xs:attribute name="role" use="required">
								<xs:simpleType>
									<xs:restriction base="xs:NMTOKEN">
										<xs:pattern value="(start|end)"/>
									</xs:restriction>
								</xs:simpleType>
							</xs:attribute>
						</xs:restriction>
					</xs:complexContent>
				</xs:complexType>
			</xs:element>
			<xs:element name="Point" minOccurs="0" maxOccurs="unbounded">
				<xs:complexType>
					<xs:complexContent>
						<xs:restriction base="point_type">
							<xs:attribute name="id" type="xs:NMTOKEN"/>
							<xs:attribute name="posRef" type="xs:NMTOKEN"/>
							<xs:attribute name="role" use="required">
								<xs:simpleType>
									<xs:restriction base="xs:NMTOKEN">
										<xs:pattern value="middle(0|[1-9][0-9]*)"/>
									</xs:restriction>
								</xs:simpleType>
							</xs:attribute>
						</xs:restriction>
					</xs:complexContent>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
		<xs:attribute name="id">
			<xs:simpleType>
				<xs:restriction base="xs:NMTOKEN">
					<xs:pattern value="Bar(0|[1-9][0-9]*)"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
		<xs:attribute name="original_id" type="xs:string"/>
		<xs:attribute name="zIndex" type="xs:string"/>
	</xs:complexType>
	<xs:unique name="roleUnique">
		<xs:selector xpath="Point"/>
		<xs:field xpath="@role"/>
	</xs:unique>
</xs:element>

But an error occurs due to the Point element appears in the same content
model more than one time, but "does'nt refer to
a type definition of the highest level".

Please post your suggestions to solve my problem.


MfG Michael Stolp
Received on Thursday, 3 November 2005 11:57:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:51 GMT