Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSD: complexType with mandatory and optional elements in arbitraryorder?

Reply
Thread Tools

XSD: complexType with mandatory and optional elements in arbitraryorder?

 
 
Thomas Wittek
Guest
Posts: n/a
 
      09-12-2007
Hi!

Is it possible to define a complexType that contains
* some elements exactly one time
* some other elements 0 or 1 times and
* some additional elements 0 to * times
-- where all elements may occur in arbitrary order?

First, I thought of xs:all, but maxOccurs cannot be greater than 1.
With xs:sequence and xs:choice I could define sub sequences with min/max
= 1/1, 0/1 and 0/* -- but I don't want to restrict the order.

Basically, I'm looking for xs:all with maxOccurs="unbounded" for some
elements.
Can you express this behavior with other definitions?

Thank you!
--
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: http://www.velocityreviews.com/forums/(E-Mail Removed)-pobox.net
GPG: 0xF534E231
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      09-13-2007
Thomas Wittek wrote:
> Is it possible to define a complexType that contains
> * some elements exactly one time
> * some other elements 0 or 1 times and
> * some additional elements 0 to * times
> -- where all elements may occur in arbitrary order?


Possible, yes. Pleasant, no; you will probably have to spell out all the
possible orders. This is one place where some of the other,
not-officially-blessed, schema languages have advantages.

The simplest solution while staying within XSD is to restrict the order.
If you've got this complicated a data structure, it's generally going to
be machine-generated anyway so leaving the order flexible doesn't buy
you much. And even humans can eventually be taught to follow directions,
if you're patient enough.

Second simplest solution is to remove the number-of-instances
constraints from the schema and implement them in the application.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
 
Thomas Wittek
Guest
Posts: n/a
 
      09-13-2007
Joe Kesselman:
> Thomas Wittek wrote:
>> Is it possible to define a complexType that contains
>> * some elements exactly one time
>> * some other elements 0 or 1 times and
>> * some additional elements 0 to * times
>> -- where all elements may occur in arbitrary order?

>
> Possible, yes. Pleasant, no; you will probably have to spell out all the
> possible orders. This is one place where some of the other,
> not-officially-blessed, schema languages have advantages.


You've got it Actually, I'm writing an extension to Atom, which is
specified in Relax NG and "assigns no significance to the order of
appearance of the child elements".
So I also wanted to allow arbitrary order within my extension.

As I also still didn't find an Atom XSD (that cannot exist due to the
lack of the missing "interleave" mode in XSD), I should probably try to
write my extension in RNG.

> The simplest solution while staying within XSD is to restrict the order.


That would be the solution of choice, if I'd stick to XSD, as I want to
do the validation with the schema and not within the application.

Thank you for the insights!
--
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: (E-Mail Removed)-pobox.net
GPG: 0xF534E231
 
Reply With Quote
 
George Bina
Guest
Posts: n/a
 
      09-13-2007
Just a note regarding "some of the other, not-officially-blessed,
schema languages have advantages": all NVDL, Relax NG and Schematron
are ISO standards.

Note that you can also have XML Schema with embedded Schematron rules.
You specify a more relaxed model in the XML Schema and add the
remaining restrictions in the embedded Schematron rules.

As you mentioned Atom extensions you may find useful also the
following recent announcement from MURATA Makoto:
http://lists.dsdl.org/dsdl-comment/2007-09/0003.html
NVDL is the simplest approach to that. More, it allows you to combine
Relax NG, XML Schema and Schematron.

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

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      09-13-2007
George Bina wrote:
> Just a note regarding "some of the other, not-officially-blessed,
> schema languages have advantages": all NVDL, Relax NG and Schematron
> are ISO standards.


Thanks for the correction; I knew they were headed in that direction but...

Of course "standard" in a rapidly-evolving environment like XML is a
misleading term, which is why the W3C explicitly doesn't use it,
preferring to call things "recommendations" until they've survived
extensive contact with the real world and are pretty clearly in final form.

My personal preference is to stick with a pure W3C solution as long as I
can, since that tends to be most widely supported and most carefully
checked for interactions with other W3C work. But I freely admit that
I'm biased, having worked on one of the recommendations.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
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
OptionParser mandatory versus optional arguments byrnejb Ruby 0 07-15-2010 04:22 PM
Making atleast one of multiple optional elements mandatory ANoobee XML 3 03-02-2007 09:31 PM
1st HD DVD Players To Decode All Mandatory, Optional Audio Codecs Allan DVD Video 0 04-10-2006 08:14 PM
Schema question regarding some mandatory/some optional values Piers Chivers XML 2 03-02-2004 09:49 AM
XML-Schema: How can I use a complexType without a certain order of elements? Wolfgang XML 2 10-07-2003 07:50 AM



Advertisments