Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD doesn't allow me to have unbounded inside all indicator

I'm trying to make unordered list of variables in var1 occurs twice and var2 occurs infinite times (Use case in my project is different). The element does not allow me to use maxOccurs.

Is there any work around for what I'm trying to do?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="testcomment">
    <xs:complexType>
      <xs:all>
        <xs:element name="var1" type="xs:string" maxOccurs="2" />
        <xs:element name="var2" type="xs:integer" maxOccurs="unbounded" />
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>
like image 976
Vignesh Avatar asked Mar 02 '10 10:03

Vignesh


People also ask

What is maxOccurs unbounded?

The maximum number of times an element may appear is determined by the value of a maxOccurs attribute in its declaration. This value may be a positive integer such as 41, or the term unbounded to indicate there is no maximum number of occurrences.

What is weak XML Schema unbounded occurrences?

Software Security | Weak XML Schema: Unbounded Occurrences. This section includes everything that is outside of the source code but is still critical to the security of the product that is being created.

What is the meaning of minOccurs 0 in XSD?

<xsd:element name="A" minOccurs="0"/> means A is optional and may appear at most once. <xsd:element name="A" maxOccurs="unbounded"/> means A is required and may repeat an unlimited number of times.


1 Answers

I came across the same problem and there is a solution! Check out this answer:

https://stackoverflow.com/a/3827606/637142

<xs:element name="A">
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:element ref="B"/>
      <xs:element ref="C"/>
    </xs:choice>
  </xs:complexType>
</xs:element>
like image 92
Tono Nam Avatar answered Oct 15 '22 04:10

Tono Nam