By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

XSD One Multiple element question

P: n/a
Hi,

I am trying to define a Key element for a vehicle schema. I have three ways
to uniquely identify a vehicle such as URN, UnitID and Vin.

I'd like to make a rule that ensures that at least one of the three is
present, but 2 or all 3 can be present. I tried something like below, but it
does not seem valid.

Thanks in advance for any assistance anyone may be able to provide. Portion
of schema is posted below. Hopefully it gives some idea as to what I am
trying to accomplish.

Best regards,

Victor

<xs:complexType name="VehKeyType">
<xs:choice>
<xs:sequence>
<!--Choice 1 URN Type is present-->
<xs:element name="URN" type="URNType">
</xs:element>
<xs:element name="UnitId" type="UnitIdType" minOccurs="0">
</xs:element>
<xs:element name="Vin" type="VinType" minOccurs="0">
</xs:element>
</xs:sequence>
<xs:sequence>
<!--Choice 2 Unit ID is present-->
<xs:element name="URN" type="URNType" minOccurs="0">
</xs:element>
<xs:element name="UnitId" type="UnitIdType">
</xs:element>
<xs:element name="Vin" type="VinType" minOccurs="0">
</xs:element>
</xs:sequence>
<xs:sequence>
<!--Choice 3 Vin is present. -->
<xs:element name="URN" type="URNType" minOccurs="0">
</xs:element>
<xs:element name="UnitId" type="UnitIdType" minOccurs="0">
</xs:element>
<xs:element name="Vin" type="VinType">
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
Mar 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
XML Schema does not allow ambiguous content so you need to be careful
when you write that. The simplest approach will be to use a relaxed
content in the XML Schema and use Schematron embedded rules to check
the constraints.
If you want an XML Schema only solution then that is possible. Imagine
you have two elements, then you will have

(a, b?) | (b, a?)

If you add another element then you will have

(a, ((b, c?) | (c, b?)) ?) | (b, ((c, a?) | (a, c?)) ?) | (c, ((a, b?)
| (b, a?)) ?)

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Mar 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.