0
I am trying to define xsd for the below xml:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<to>Tove</to>
</note>
I have defined below xsd for above. 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="note">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded" minOccurs="0">
        <xs:element type="xs:string" name="to"/>
        <xs:element type="xs:string" name="from"/>
        <xs:element type="xs:string" name="heading"/>
        <xs:element type="xs:string" name="body"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

But the tricky part here is how can i define only "to" element repeated any number of times and in any order but "from", "heading", "body" repeated only once.How to keep this kind of restriction in the xsd.

rajee
  • 15
  • 6
  • 1
    where are you validating? as this can be done without much effort in xsd 1.1 – Jayvee Dec 21 '21 at 16:58
  • i am validating above using msxml. Here under one parent element i need to define few elements with one property like to be not repeated and other to be repeated in any order. but i did not get my answer anywhere – rajee Dec 22 '21 at 05:28
  • 1
    You may need a XSD 1.1 validator and use xs:all or xs:assert to achieve what you want. In Python for instance you can use the library xmlschema. There also are libraries for other languages but not all them are free. – Jayvee Dec 22 '21 at 17:17
  • Thank you @Jayvee i have tried with xs:all but i did not get exact solution – rajee Dec 25 '21 at 11:51
  • 1
    Have a look at xs:assert that will let you test the count of each element within the complexType – Jayvee Dec 25 '21 at 11:55
  • Thank you @Jayvee i have tried with xs:all but i did not get exact solution. Could you please suggest me exact code if you can.That will be very help ful to me. i did not find any thing related to it also – rajee Dec 25 '21 at 11:58
  • 1
  • s4s-elt-must-match.1: The content of 'choice' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found starting at: assert. Getting this error – rajee Dec 25 '21 at 12:56

0 Answers0