我在 W3C XML 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 是 2^32-1 所以,很明显,xmllint 实现了带符号的 32 位数字的整数,这还不够。
xmllint 对吗?该标准显然不限制整数的大小:
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
nonNegativeInteger 的值空间是无限集 {0,1,2,...}。
所以,实现者应该使用无限整数......
最佳实践是什么?
实现者应该使用 bigints 还是类似的东西?(在这种情况下, xmllint 是错误的。)
模式作者是否应该将自己限制为 maxOccurs 的“合理”值?(在这种情况下,我会将问题报告给架构作者。)