0

I would like to validate my XML using an XSD. The XML is supposed to contain complex elements with some (none to all) elements of a given set. I think the straight foward solution for the complex element is

<xs:sequence>
  <xs:element name="foo" minOccurs="0" maxOccurs="1"/> 
  <xs:element name="bar" minOccurs="0" maxOccurs="1"/> 
  <xs:element name="bee" minOccurs="0" maxOccurs="1"/> 
</xs:sequence>

I want to get rid of the set order of elements, plus I want to get rid of the minOccurs="0" in every line, so that

<foo>text</foo>
<bee>text</bee> 
<bar>text</bar>

is also valid. My idea was to write

<xs:sequence minOccurs="0" maxOccurs="unbounded">
   <xs:choice minOccurs="0" maxOccurs="unbounded"> 
      <xs:element1>
      <xs:element2> 
      ... 
   </xs:choice>
</xs:sequence>

which should translate to "select one element of the list as many times as you want to."

But it does not allow me to put an appearance restriction (like maxOccurs=1) on individual elements. Is there a better way to validate an XML without forcing a given order of elements?

Anselm G
  • 1
  • 1
  • Which version of XSD do you use? Have you looked at `xs:all`? Also, it would help if you explain in more detail which instances samples you want to consider valid and which ones invalid. – Martin Honnen Jan 31 '22 at 13:34
  • `xs:all´ does not support elements with maxOccurs>1 as far as I understood it. But yes it is also a possibility. – Anselm G Jan 31 '22 at 13:48
  • I use no specific XSD version but XML 1.0 (first line: ). I am quite new to this, so there might be room for improvement... – Anselm G Jan 31 '22 at 13:57
  • XSD 1.1 "allows arbitrary values of minOccurs and maxOccurs on the particles of a model group using the compositor xs:all", thus, newer versions of Xerces or Saxon support that, as does Altova. – Martin Honnen Jan 31 '22 at 14:03
  • Thanks! I'll look into that further :) – Anselm G Jan 31 '22 at 15:12

0 Answers0