tags:

views:

568

answers:

2

I work on a W3C XML Schema (not written by me). One tool, xmllint, refuses to use the schema:

traceroute.xsd:658: element element: Schemas parser error : Element
 '{http://www.w3.org/2001/XMLSchema}element', attribute 'maxOccurs': The value
 '4294967295' is not valid. Expected is '(xs:nonNegativeInteger | unbounded)'.

4294967295 is 2^32-1 so, clearly, xmllint implements integers with signed 32bits number and that's not enough.

Is xmllint right? The standard apparently does not limit the size of integers:

http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#p-max_occurs http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#nonNegativeInteger

The value space of nonNegativeInteger is the infinite set {0,1,2,...}.

So, implementors are supposed to use infinite integers...

What are the best practices?

Should implementors use bigints or similar things? (In that case, xmllint is wrong.)

Should schema authors limit themselves to "reasonable" values for maxOccurs? (In that case, I will report the issue to the schema authors.)

+4  A: 

While perhaps being a 'technically' correct usage of the maxOccurs attribute, this usage isn't (IMO) how the maxOccurs is intended to be used.

It looks like the schema writer intended to mean that this element may occur any number of times, in which case the correct value of the definition would be unbounded.

What the current definition implies is that the systems consuming this schema will behave perfectly correctly for element counts up to 4294967295 but will fail for anything larger.

I suppose this is a technical requirement that could make sense - lots of systems will have int32 coded as the maximum number of elements so in an ideal world you might want to enforce this limit, but I don't think it is really a reasonable or useful thing to try and capture in a schema in the real world.

Also, if you are sending that many elements, then XML is probably the wrong data format.

I'd suggest that the schema authors use the unbounded attribute value, or use values that actually match the limitations and requirements of the systems consuming this XML.

David Hall
+1  A: 

Finally, the schema has been modified by its authors. It has been published in RFC 5388 and it now contains:

     <xs:element maxOccurs="2147483647" minOccurs="0"
                 name="Measurement">
       <xs:complexType>
         <xs:sequence>
bortzmeyer