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

XSD: Definition abhängig von Attributwert

72 views
Skip to first unread message

Thomas Schremser

unread,
Mar 19, 2012, 3:34:32 AM3/19/12
to
Hallo allerseits!

Meine Applikation l��t sich �ber eine XML-Datei konfigurieren. In dieser XML-Datei gibt es
ein Element namens Mappings, das ein Attribut namens Typ angeben mu�. Ein Mappings-Element
enth�lt dann ein oder mehrere Elemente namens Mapping, die zumindest das Attribut ID angeben
m�ssen. Folgende XML-Fragmente sind in meiner Applikation g�ltig:

<Mappings Type="Fixed">
<Mapping ID="Hdr"/>
</Mappings>

<Mappings Type="Variable" KeyStart="1" KeyLength="1">
<Mapping Key="D" ID="03D"/>
<Mapping Key="L" ID="03L"/>
<Mapping Key="H" ID="03H"/>
<Mapping Key="B" ID="03B"/>
</Mappings>

Zum Validieren verwende ich folgendes Schema:

<xsd:complexType name="Mappings">
<xsd:sequence>
<xsd:element name="Mapping" type="Mapping" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="Type" type="MappingsType" use="required"/>
<xsd:attribute name="KeyStart" type="xsd:positiveInteger"/>
<xsd:attribute name="KeyLength" type="xsd:positiveInteger"/>
</xsd:complexType>

<xsd:simpleType name="MappingsType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Variable"/>
<xsd:enumeration value="Fixed"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Mapping">
<xsd:attribute name="Key" type="xsd:string"/>
<xsd:attribute name="ID" type="xsd:string" use="required"/>
</xsd:complexType>

Soweit funktioniert das auch. Was ich nun m�chte, ist, da� Mappings wenn der Typ "Fixed" ist,
keine weiteren Attribute enth�lt und nur ein einziges Mapping-Element, das wiederum das
Key-Attribut nicht enth�lt. Umgekehrt sollen beim Typ "Variable" die Attribute KeyStart und
KeyLength verpflichtend sein, ebenso das Attribut Key im Mapping-Element, wobei hier nun auch
mehr als ein Mapping-Element erlaubt sind. Folgende XML-Fragmente w�ren also ung�ltig:

<Mappings Type="Fixed" KeyStart="1" KeyLength="1">
<Mapping ID="Hdr"/>
</Mappings>

<Mappings Type="Fixed">
<Mapping ID="Hdr"/>
<Mapping ID="Dta"/>
</Mappings>

<Mappings Type="Variable" KeyLength="1">
<Mapping Key="D" ID="03D"/>
<Mapping Key="L" ID="03L"/>
</Mappings>

<Mappings Type="Variable" KeyStart="1" KeyLength="1">
<Mapping ID="03D"/>
<Mapping ID="03L"/>
</Mappings>

L��t sich das als Schema definieren?

TIA

Gr��e
Thomas

--
Any problem in computer science can be solved with another layer
of indirection. But that usually will create another problem.
David Wheeler

Gr��e
Thomas

--
Any problem in computer science can be solved with another layer
of indirection. But that usually will create another problem.
David Wheeler

Martin Honnen

unread,
Mar 19, 2012, 8:41:30 AM3/19/12
to
Thomas Schremser wrote:

> Was ich nun m�chte, ist, da� Mappings wenn der Typ "Fixed" ist,
> keine weiteren Attribute enth�lt und nur ein einziges Mapping-Element, das wiederum das
> Key-Attribut nicht enth�lt. Umgekehrt sollen beim Typ "Variable" die Attribute KeyStart und
> KeyLength verpflichtend sein, ebenso das Attribut Key im Mapping-Element, wobei hier nun auch
> mehr als ein Mapping-Element erlaubt sind. Folgende XML-Fragmente w�ren also ung�ltig:
>
> <Mappings Type="Fixed" KeyStart="1" KeyLength="1">
> <Mapping ID="Hdr"/>
> </Mappings>
>
> <Mappings Type="Fixed">
> <Mapping ID="Hdr"/>
> <Mapping ID="Dta"/>
> </Mappings>
>
> <Mappings Type="Variable" KeyLength="1">
> <Mapping Key="D" ID="03D"/>
> <Mapping Key="L" ID="03L"/>
> </Mappings>
>
> <Mappings Type="Variable" KeyStart="1" KeyLength="1">
> <Mapping ID="03D"/>
> <Mapping ID="03L"/>
> </Mappings>
>
> L��t sich das als Schema definieren?

Mit der derzeitigen Version 1.0 der Schemasprache meines Wissens nicht,
in der Version 1.1, die kurz vor der Fertigstellung steht, gibt es
http://www.w3.org/TR/xmlschema11-1/#cTypeAlternative. Von Xerces gibt es
glaube ich schon eine Version, die das unterst�tzt.
F�r ein Beispiel siehe
http://www.ibm.com/developerworks/library/x-xml11pt2/#N103D7, aber
beachte, dass ich nicht gepr�ft habe, ob das Beispiel genau auf dem
aktuellen Stand der Schemasprache ist, die ja noch unter Entwicklung ist.

--

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

Thomas Schremser

unread,
Mar 20, 2012, 5:03:14 AM3/20/12
to
Hallo Martin!

> Mit der derzeitigen Version 1.0 der Schemasprache meines Wissens nicht,
> in der Version 1.1, die kurz vor der Fertigstellung steht, gibt es
> http://www.w3.org/TR/xmlschema11-1/#cTypeAlternative.

Danke für die Info; für mein aktuelles Programm nützt es mir zwar nichts mehr,
für zukünftige Projekte ist es aber gut zu wissen.

Grüße
0 new messages