Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Elements with maxOccurs (some unbound, some 1)

Reply
Thread Tools

Elements with maxOccurs (some unbound, some 1)

 
 
foolproofplan@gmail.com
Guest
Posts: n/a
 
      05-22-2007
Maybe I am looking to far into a simple problem, but I am having quite
a hard time figuring this out:

I am currently trying to create a schema to represent an Element which
contains other Elements (some of which have a restriction on how many
can occur). Here is an example of what I have done if that seems
confusing:

<xsd:element name="Object">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element ref="License" minOccurs="0"/>
<xsd:element ref="NameMemberReference" minOccurs="0"
maxOccurs="1"/>
<xsd:element ref="ParentMemberReference" minOccurs="0"
maxOccurs="1"/>
<xsd:element ref="Members"/>
<xsd:element ref="OnEdit" minOccurs="0"/>
<xsd:element ref="OnCommit" minOccurs="0"/>
<xsd:element ref="Permissions" minOccurs="0"/>
</xsd:choice>
<xsd:attribute ref="name" use="required"/>
</xsd:complexType>
</xsd:element>

I think the trouble with this is that the two elements that need to be
restricted to one occurance (NameMememberReference and
ParentMemberReference) are within an unbounded choice so they still
can be created multiple times.

I've played around with some other idea by using a Choice and an All
and I've also trying making groups but nothing has seemed to solve my
problem. Any ideas?

Thanks,
- Marc

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      05-22-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Any ideas


Do you really need to leave the order unconstrained? If you're willing
to nail down the order slightly, factor the two maxOccurs='1' items out
and enclose them and the choice in a sequence.

Or make the whole thing a sequence and just require folks to give the
contents in that specific order, if there isn't a good reason to let
them randomly intermix the contents.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
 
foolproofplan@gmail.com
Guest
Posts: n/a
 
      05-23-2007
Joseph Kesselman <(E-Mail Removed)> wrote:
> Do you really need to leave the order unconstrained?


Yep, the order is going to have to be left open. It's something beyond
my control.

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      05-23-2007
If it was just a single constrained element, I'd suggest breaking it up
into submodels -- any mixture of the others, that one, any mixture of
the others.

With two, and being unwilling to constrain their order... I think you
can do it by combining that idea with Martin's solution in the thread
entitled "Xml Schema OR, XOR", breaking things down into non-redundant
cases. But you're going to wind up with a lot of copy-and-repeat Schema
code to express that.

There may be a better solution; my schema skills aren't supurb.

There's always the alternative of applying the at-most-one constraint in
applications (semantic validation) rather than in schemas (higher-level
syntactic validation).

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Elements with maxOccurs (some unbound, some 1) foolproofplan@gmail.com XML 1 05-24-2007 08:55 PM
Re: Elements with maxOccurs (some unbound, some 1) foolproofplan@gmail.com XML 2 05-23-2007 06:45 PM
XML Schema --- <xs:choice maxOccurs=5> hooomee@gmail.com XML 2 06-05-2006 09:58 PM
The usage of <xs:choice maxOccurs="unbounded"> mavis XML 2 06-01-2006 05:02 PM
The usage of <xs:choice maxOccurs="unbounded"> Mavis Java 0 06-01-2006 06:12 AM



Advertisments