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

3

19

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>
Chromatid answered 2/3, 2010 at 10:15 Comment(1)
D
2

What you're trying to do sounds like the type of an element in your list might be ambiguous without reading-ahead, in which case there's no work around in XSD because of the classes of languages it can describe.

Can you post up a the relevant part of your XSD?


Update: No, you can't do that with XSD. The rules about what you can put in an <xs:all> element are listed for example here. This constraint has a name - the UPA, or Unique Particle Attribution constraint. It's all to do with ambiguity and the Microsoft website has a good explanation of why is exists here.

You can either change your document layout to remove the need for this kind of declaration, or look to a more expressive schema language like RelaxNG.

Devitrify answered 2/3, 2010 at 10:18 Comment(1)
You did, a few minutes ago. Post it back, highlight it and click the little button on the editor that looks like binary (10101) and it will indent your XML, which will make it show properly.Devitrify
D
17

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

https://mcmap.net/q/667161/-xml-schema-to-match-the-following-quot-all-quot-with-unbounded-maxoccurs

<xs:element name="A">
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:element ref="B"/>
      <xs:element ref="C"/>
    </xs:choice>
  </xs:complexType>
</xs:element>
Doucet answered 10/5, 2013 at 15:14 Comment(1)
This answer would be more useful if it worked with the example from the question.Laveralavergne
A
7

easy, simply use<xs:choice maxOccurs="unbounded"> instead of <xs:all>. This will give the effect you are looking for.

Alaynaalayne answered 1/3, 2014 at 2:5 Comment(0)
D
2

What you're trying to do sounds like the type of an element in your list might be ambiguous without reading-ahead, in which case there's no work around in XSD because of the classes of languages it can describe.

Can you post up a the relevant part of your XSD?


Update: No, you can't do that with XSD. The rules about what you can put in an <xs:all> element are listed for example here. This constraint has a name - the UPA, or Unique Particle Attribution constraint. It's all to do with ambiguity and the Microsoft website has a good explanation of why is exists here.

You can either change your document layout to remove the need for this kind of declaration, or look to a more expressive schema language like RelaxNG.

Devitrify answered 2/3, 2010 at 10:18 Comment(1)
You did, a few minutes ago. Post it back, highlight it and click the little button on the editor that looks like binary (10101) and it will indent your XML, which will make it show properly.Devitrify

© 2022 - 2024 — McMap. All rights reserved.