XSD: complexType with mandatory and optional elements in arbitraryorder?

T

Thomas Wittek

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!
 
J

Joe Kesselman

Thomas said:
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.
 
T

Thomas Wittek

Joe Kesselman:
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!
 
G

George Bina

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
 
J

Joe Kesselman

George said:
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.
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top