Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Schema-Problem: Elemente mit unterschiedlichem maxOccurs

19 views
Skip to first unread message

Franz Kruse

unread,
Mar 17, 2012, 6:17:59 PM3/17/12
to
Ich suche nach einer Möglichkeit, im Schema zu spezifizieren, dass

- Elemente a und b maximal einmal vorkommen dürfen,
- Element x beliebig oft vorkommen darf,
- die Reihenfolge beliebig ist,

also z. B.:

<root>
<a/>
<x/>
<x/>
<b/>
<x/>
</root>

Die naheliegende Lösung geht leider nicht:

<xsd:all>
<xsd:element name="a" minOccurs="0" maxOccurs="1"/>
<xsd:element name="b" minOccurs="0" maxOccurs="1"/>
<xsd:element name="x" minOccurs="0" maxOccurs="unbounded"/>
</xsd:all>

Hat jemand eine gute Idee? Oder vielleicht einen guten Kompromissvorschlag?

Franz

Martin Honnen

unread,
Mar 18, 2012, 7:11:46 AM3/18/12
to
Schau dir eventuell mal das Schema für das "head"-Element in XHTML
(http://www.w3.org/TR/xhtml1-schema/#xhtml1-strict) an, das darf ja
genau ein "title" und ein optionales "base"-Element haben, und ansonsten
beliebig viele "meta", "script", "style".

<xs:group name="head.misc">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="script"/>
<xs:element ref="style"/>
<xs:element ref="meta"/>
<xs:element ref="link"/>
<xs:element ref="object"/>
</xs:choice>
</xs:sequence>
</xs:group>

<xs:element name="head">
<xs:annotation>
<xs:documentation>
content model is "head.misc" combined with a single
title and an optional base element in any order
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:group ref="head.misc"/>
<xs:choice>
<xs:sequence>
<xs:element ref="title"/>
<xs:group ref="head.misc"/>
<xs:sequence minOccurs="0">
<xs:element ref="base"/>
<xs:group ref="head.misc"/>
</xs:sequence>
</xs:sequence>
<xs:sequence>
<xs:element ref="base"/>
<xs:group ref="head.misc"/>
<xs:element ref="title"/>
<xs:group ref="head.misc"/>
</xs:sequence>
</xs:choice>
</xs:sequence>
<xs:attributeGroup ref="i18n"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="profile" type="URI"/>
</xs:complexType>
</xs:element>


Ansonsten ist die Version 1.1 der Schemasprache fast fertig, das kann
xs:all auch mehr (http://www.w3.org/TR/xmlschema11-1/#ch_models) als in
1.0, von Apache Xerces gibt es schon Versionen, die das unterstützen.
Eventuell ist das eine Möglichkeit.

--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
0 new messages