简体   繁体   English

W3C XML模式和maxOccurs的最大整数

[英]W3C XML Schema and the maximum integer for maxOccurs

I work on a W3C XML Schema (not written by me). 我正在研究W3C XML Schema(不是我写的)。 One tool, xmllint, refuses to use the schema: 一种工具xmllint拒绝使用该模式:

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. 4294967295是2 ^ 32-1,因此,显然,xmllint实现了带符号32位数字的整数,这还不够。

Is xmllint right? xmllint对吗? 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 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,...}. nonNegativeInteger的值空间是无限集{0,1,2,...}。

So, implementors are supposed to use infinite integers... 因此,实现者应该使用无限整数...

What are the best practices? 最佳做法是什么?

Should implementors use bigints or similar things? 实现者应该使用bigints还是类似的东西? (In that case, xmllint is wrong.) (在这种情况下,xmllint是错误的。)

Should schema authors limit themselves to "reasonable" values for maxOccurs? 模式作者是否应该将自己限制在maxOccurs的“合理”值? (In that case, I will report the issue to the schema authors.) (在这种情况下,我将把问题报告给模式作者。)

While perhaps being a 'technically' correct usage of the maxOccurs attribute, this usage isn't (IMO) how the maxOccurs is intended to be used. 虽然可能是maxOccurs属性的“技术上”正确用法,但这种用法(IMO)并非旨在使用maxOccurs

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 . 看起来,架构编写器意图表示此元素可以出现任意次,在这种情况下,定义的正确值将是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. 当前定义暗示的是,使用此架构的系统对于最多4294967295元素计数将表现完全正确,但对更大的元素将失败。

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. 我想这是一个可能有意义的技术要求-许多系统将int32编码为最大元素数,因此在理想情况下,您可能希望强制执行此限制,但我认为这确实不合理或尝试在现实世界中的模式中捕获有用的东西。

Also, if you are sending that many elements, then XML is probably the wrong data format. 另外,如果要发送那么多元素,则XML可能是错误的数据格式。

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. 我建议架构作者使用unbounded属性值,或者使用实际上与使用此XML的系统的限制和要求匹配的值。

Finally, the schema has been modified by its authors. 最后,该架构已被其作者修改。 It has been published in RFC 5388 and it now contains: 它已在RFC 5388中发布,现在包含:

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

The maximum value for maxOccurs is 4095. maxOccurs的最大值为4095。
If you want more, set it to "unbounded". 如果需要更多,请将其设置为“ unbounded”。
Reference: https://docs.microsoft.com/en-us/biztalk/core/technical-reference/max-occurs-node-property-of-all-schemas 参考: https : //docs.microsoft.com/zh-cn/biztalk/core/technical-reference/max-occurs-node-property-of-all-schemas

Hope this help! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM