Multi-Key in XML-Schema

roggr11

Usenet Archive
Joined
Aug 22, 2007
Messages
1
Reaction score
0
Hi,
I'm trying to define an XSD which allows me to have a multi-keyed XML- Node in the target-XML-files. Here's a shortened structure of such a file:

<GenericElement
xmlns="http://www.somens.com/elements"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.somens.com/elements GenericElement.xsd" >

<ConfigDialog>
<Page Id="dlg1">
<ChannelParameter IdVariable="1" />
</Page>
<Page Id="dlg2">
<ChannelParameter IdVariable="2" />
<ChannelParameter IdVariable="3" />
</Page>
</ConfigDialog>

<Channels>
<Channel>
<ChannelParameterRef IdConfigPage="dlg1"
IdConfigPageVariable="1" />
<ChannelParameterRef IdConfigPage="dlg2"
IdConfigPageVariable="2" />
<ChannelParameterRef IdConfigPage="dlg2"
IdConfigPageVariable="3" />
</Channel>
</Channels>
</GenericElement>

The ChannelParameterRef-Nodes point to ChannelParameter-Nodes inside the various Page-Nodes. I need to find a way that you cannot make wrong references (for example, IdConfigPage="dlg1" and IdConfigPageVariable="2").

My current schema looks like this:

<xs:schema targetNamespace="http://www.somens.com/elements" xmlns="http://www.somens.com/elements" xmlns:NS="http://www.somens.com/ elements" xmlns:xs="http://www.somens.com/elements" elementFormDefault="qualified"> <xs:complexType name="GenericElementT"> <xs:sequence> <xs:element name="ConfigDialog" type="ConfigDialogT" /> <xs:element name="Channels"> <xs:complexType> <xs:sequence maxOccurs="unbounded"> <xs:element name="Channel" type="ChannelT" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType>

<xs:element name="GenericElement" type="GenericElementT"> <xs:key name="ChannelParameterKey"> <xs:selector xpath="NS:ConfigDialog/NS:page" /> <xs:field xpath="@Id" /> <xs:field xpath="child::NS:ChannelParameter/@IdVariable" /> </xs:key> <xs:keyref name="RefChannelParameterKey" refer="ChannelParameterKey"> <xs:selector xpath="NS:Channels/NS:Channel/
NS:ChannelParameterRef" />
<xs:field xpath="@IdConfigPage" />
<xs:field xpath="@IdConfigPageVariable" />
</xs:keyref>
</xs:element>

<xs:complexType name="ConfigPageT">
<xs:sequence maxOccurs="unbounded">
<xs:element name="ChannelParameter"
type="ChannelParameterVariableT" minOccurs="0" maxOccurs="unbounded"> </xs:element> </xs:sequence> <xs:attribute name="Id" type="xs:string" use="required" /> </xs:complexType>

<xs:complexType name="ConfigDialogT">
<xs:sequence maxOccurs="unbounded">
<xs:element name="Page" type="ConfigPageT" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType>

<xs:complexType name="ChannelT">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="ChannelParameterRef"
type="ChannelParameterRefT" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType>

<xs:attribute name="IdConfigPageVariable" type="xs:int" use="required" /> </xs:complexType>

<xs:complexType name="ChannelParameterVariableT">
<xs:attribute name="IdVariable" type="xs:int" use="required" /> </xs:complexType> </xs:schema>

This unfortunately doesn't work because I have multiple ChannelParameter-Nodes inside a Page-Node.

My question is: is it actually possible to define such a relationship in an XSD? And if so, can you give me a hint what's wrong with my approach and how to solve it?

Thanks in advance,
mfg Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top