XSD - <xs:all> with a <xs:choice> within it.

I am trying to create a schema for a Directory.

Currently I have an <xs:sequence> within the <Directory>, I wish to change this to <xs:all>, but then the <xs:choice> is not valid.

As it stands, the <xs:sequence> is incorrect as I dont wish the schema to enforce a strict order of elements, nor is it required that they all exist (except 'name').

I have tried using another 'elemen't with a 'substitionGroup', but this did not work because a Directory can contain further directories and i was not able to add  maxOccurs="unbounded"> to my new 'element'

Any help will be appreciated.

Thanks
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:complexType name="directory">
		<xs:sequence>
			<xs:element name="name" type="xs:string"/>
			<xs:element name="size" type="xs:string" minOccurs="0"/>
			<xs:element name="colour" type="xs:string" minOccurs="0"/>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:element name="dateTimes" type="xs:string"/>
				<xs:element name="dateTimesV2" type="xs:string"/>
			</xs:choice>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:choice minOccurs="0" maxOccurs="unbounded">
					<xs:element name="dir" type="directory"/>
					<xs:element name="dirV2" type="directory"/>
				</xs:choice>
				<xs:choice minOccurs="0" maxOccurs="unbounded">
					<xs:element name="file" type="file"/>
					<xs:element name="fileV2" type="file"/>
				</xs:choice>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="file">
		<xs:sequence>
			<xs:element name="name" type="xs:string"/>
			<xs:element name="size" type="xs:string" minOccurs="0"/>
			<xs:element name="colour" type="xs:string" minOccurs="0"/>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:element name="dateTimes" type="xs:string"/>
				<xs:element name="dateTimesV2" type="xs:string"/>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>

</xs:schema

Open in new window

MolkoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
restrictions on xs:all are very strict,
because there always is a risk of ambiguous models
specially when you have choices and minoccurs0, you can forget about xs:all
(actually xs:all is so strict that I hardly ever use it in my schemes)

On top of that it is not a bad idea at all to be more strict from the schema side
meaning that I usually recommend to use a strict sequence and possibly filter the data prior to validation
( a simple XSLT that orders the elements prior to validation)

If you don't want, nor can do that, you can make the xsd less strict
by using a choice with macOccurs unbounded on the choice
and use Schatron (www.schematron.com) on top of the XSD, to take care of the counts restrictions
0
MolkoAuthor Commented:
THanks

so is there now real solution to my problem, so if leave it as xs:sequence, how do i deal with elements that are not in the correct sequence ? I dont want to go down the root of ordering prior via xslt.
0
Geert BormansInformation ArchitectCommented:
there is no real solution, parsers are supposed not to do backtracking, so quite some ambiguous models can simply not be expressed in xsd.
If you don't want to go down the route of ordering in XSLT prior to validation, I am afraid xs:sequence is going to be too strict for you, it is not helpfull
schematron and xs:choice might be helpfull?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MolkoAuthor Commented:
:-) Thanks
0
Geert BormansInformation ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.