123MilitaryNerd
123MilitaryNerd

Reputation: 213

XSD for XML file that has xs:all followed by xs:choice or xs:sequence

I have an XML file that looks like the following:

<root>
    <node1></node1>
    <node2></node2>
    <node3></node3>
    <line>
       <line1></line1>
       <line2></line2>
       <line3></line3>
    </line>
    <line>
       <line1></line1>
       <line2></line2>
       <line3></line3>
    </line>
</root>

Here are my restrictions:

I'm trying to design an XSD file to validate this XML, but to no avail. The problem is that I'm essentially looking at an <xs:all> block (for my <node#>s) followed by an <xs:sequence> or <xs:choice> block with maxOccurs="unbounded" (for my <line>s), but it seems like there's no valid way to do this with XSD 1.0.

Upvotes: 0

Views: 59

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

There are only six possible sequences of (1,2,3) appearing once each in any order, so it's feasible to enumerate them all. Of course this doesn't scale but it might work for you. That would be

(1((2,3)|(3,2)) | 2((1,3)|(3,1)) | 3((1,2)|(2,1))

using "," for sequence and "|" for choice.

Your only other options are not XSD 1.0. E.g. XSD 1.1 or schematron.

Upvotes: 1

Related Questions