Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Using XML Schema to Force At Least One Item? (http://www.velocityreviews.com/forums/t169086-using-xml-schema-to-force-at-least-one-item.html)

Kenneth Love 04-01-2005 04:52 PM

Using XML Schema to Force At Least One Item?
 
Sorry if this is a newbie question. I couldn't get the correct magic
incantation for Google to get an answer. :-(

I'm trying to satisfy a requirement that "at least one of the following
*must* be present" in an XML Schema. I have come up with two examples
that almost work.

Here's the first:

<xs:element name="LightExample1" maxOccurs="3">
<xs:complexType>
<xs:choice>
<xs:element name="A"/>
<xs:element name="B"/>
<xs:element name="C"/>
</xs:choice>
</xs:complexType>
</xs:element>

This doesn't work because it allows multiple A, B, or C elements.

Here's the second example:

<xs:element name="LightExample2">
<xs:complexType>
<xs:sequence>
<xs:element name="A" minOccurs="0"/>
<xs:element name="B" minOccurs="0"/>
<xs:element name="C" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>

This *almost* works. The only problem is that it allows an empty
<LightExample2/> element which fails the "at least one of" portion of
the requirement.

Is it possible to do this?

Kenneth


Martin Honnen 04-01-2005 05:08 PM

Re: Using XML Schema to Force At Least One Item?
 

Kenneth Love wrote:

> I'm trying to satisfy a requirement that "at least one of the following
> *must* be present" in an XML Schema. I have come up with two examples
> that almost work.
>
> Here's the first:
>
> <xs:element name="LightExample1" maxOccurs="3">
> <xs:complexType>
> <xs:choice>
> <xs:element name="A"/>
> <xs:element name="B"/>
> <xs:element name="C"/>
> </xs:choice>
> </xs:complexType>
> </xs:element>
>
> This doesn't work because it allows multiple A, B, or C elements.


Why do multiple elements conflict with your sole requirement "at least
one of the following *must* be present"?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Kenneth Love 04-01-2005 07:05 PM

Re: Using XML Schema to Force At Least One Item?
 
Okay. I guess I left out the requirement that no more than one of each
element A, B, or C can appear in the result.

ABC is valid. C is valid. AA is not. CBC is not.

The order is not that important to me. If I was provided a solution
forcing the elements to be in a certain order then that's okay. It's
okay if the solution provides for the elements to be in any order. I
would prefer the former, actually.

I could write a regular expression like this:

RE = (A, B?, C?) | (A?, B, C?) | (A?, B?, C)

Any thoughts?

adTHANKSvance,
Kenneth Love



All times are GMT. The time now is 02:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57