Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Validation bug

Help
2010-01-05
2013-05-01
  • PixelPusher
    PixelPusher
    2010-01-05

    Jaxe does not find the XML to be invalid when multiple elements, nor does it prevent me from adding multiple elements, within an xs:choice occur in the XML, but I think it should when the schema is defined with each element having maxOccurs="1". Is this a mistake in my understanding of XML validation or Jaxe's?

    I have an element in my XML schema that provides a list of options that I want to allow only once, but in any order.

        <xs:element name="FileTypes">
          <xs:complexType>
             <xs:choice maxOccurs="unbounded">
               <xs:element maxOccurs="1"  minOccurs="0" name="Log" />
               <xs:element maxOccurs="1"  minOccurs="0" name="Txt" />
               <xs:element maxOccurs="1"  minOccurs="0" name="Png" />
               <xs:element maxOccurs="1"  minOccurs="0" name="Mp3" />
             </xs:choice>
          </xs:complexType>
        </xs:element>

    I can  make this an xs:sequence, which limits each element to only one occurrence, but that doesn't allow the order independence that I need. Alternatively, I can use the xs:choice as shown above, which give the order-independence, but Jaxe won't limit the elements to only one occurrence.

     
  • > Jaxe does not find the XML to be invalid when multiple elements, nor does it prevent me from adding multiple elements, within an xs:choice occur in the XML, but I think it should when the schema is defined with each element having maxOccurs="1". Is this a mistake in my understanding of XML validation or Jaxe's?

    I think you misunderstand: if you have maxOccurs="unbounded" for the choice, you can add as many elements as you want.

    > I can make this an xs:sequence, which limits each element to only one occurrence, but that doesn't allow the order independence that I need. Alternatively, I can use the xs:choice as shown above, which give the order-independence, but Jaxe won't limit the elements to only one occurrence.

    This is a common dilemma when designing W3C XML schemas. xs:all might solve the problem in some cases, but it has severe restrictions, so even if Jaxe handled it perfectly you would still stumble upon this problem every once in a while. I usually choose to use xs:sequence when I have this problem. I think Relax-NG handles that better.

     
  • PixelPusher
    PixelPusher
    2010-01-06

    Once again, thanks for your help!

    > I think you misunderstand: if you have maxOccurs="unbounded" for the choice, you can add as many elements as you want.

    I guess you are correct. There is a lot here that I don't understand. I thought the maxOccurs="1" on the element would enforce the single occurrence limit.

    > I usually choose to use xs:sequence when I have this problem.

    That is the path I will probably have to take, as well.

    Thanks again.<br>
    Thom