问题描述
我在研究 W3C XML 模式(不是我写的).一种工具,xmllint,拒绝使用架构:
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 是 2^32-1 所以,很明显,xmllint 实现了整数有符号的 32 位数字,这还不够.
4294967295 is 2^32-1 so, clearly, xmllint implements integers withsigned 32bits number and that's not enough.
xmllint 对吗?该标准显然没有限制大小整数:
Is xmllint right? The standard apparently does not limit the size ofintegers:
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#p-max_occurshttp://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#nonNegativeInteger
nonNegativeInteger 的值空间是无限集 {0,1,2,...}.
因此,实现者应该使用无限整数...
So, implementors are supposed to use infinite integers...
最佳做法是什么?
实现者应该使用 bigint 或类似的东西吗?(在这种情况下,xmllint 是错误的.)
Should implementors use bigints or similar things? (In that case,xmllint is wrong.)
模式作者是否应该将自己限制为合理"的值最大发生次数?(在这种情况下,我会将问题报告给架构作者.)
Should schema authors limit themselves to "reasonable" values formaxOccurs? (In that case, I will report the issue to the schemaauthors.)
推荐答案
虽然可能是 maxOccurs
属性的技术上"正确用法,但这种用法不是 (IMO) maxOccurs
旨在使用.
While perhaps being a 'technically' correct usage of the maxOccurs
attribute, this usage isn't (IMO) how the maxOccurs
is intended to be used.
看起来模式编写者的意图是这个元素可能出现任意次数,在这种情况下,定义的正确值将是unbounded
.
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
.
当前定义所暗示的是,使用此模式的系统对于元素计数高达 4294967295
的系统将表现得非常正确,但对于任何更大的元素都会失败.
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.
我认为这是一个有意义的技术要求 - 许多系统将 int32
编码为最大元素数,因此在理想世界中,您可能希望强制执行此限制,但我不要认为尝试在现实世界中的模式中捕获真的是一件合理或有用的事情.
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.
此外,如果您要发送这么多元素,那么 XML 可能是错误的数据格式.
Also, if you are sending that many elements, then XML is probably the wrong data format.
我建议架构作者使用 unbounded
属性值,或者使用实际匹配使用此 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.
这篇关于W3C XML Schema 和 maxOccurs 的最大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!