java XMLSchema 不支持大于 5000 的 maxOccurs 的解决方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16651005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Workaround for XMLSchema not supporting maxOccurs larger than 5000
提问by mzywiol
My problem is with parsing an XSD Schema that has elements with maxOccurs
larger than 5000 (but not unbounded
).
我的问题是解析元素maxOccurs
大于 5000(但不是unbounded
)的 XSD 架构。
This is actually a know issue in either Xerces (which I'm using, version 2.9.1) or JAXP, as described here: http://bugs.sun.com/view_bug.do;jsessionid=85335466c2c1fc52f0245d20b2e?bug_id=4990915
这实际上是 Xerces(我正在使用的版本 2.9.1)或 JAXP 中的一个已知问题,如下所述:http://bugs.sun.com/view_bug.do;jsessionid=85335466c2c1fc52f0245d20b2e?bug_id= 4990915
I already know that if I changed the maxOccurs numbers in my XSD from numbers larger than 5000 to unbounded
all works well. Sadly, this is not an optionin my case (I cannot meddle with the XSD file).
我已经知道,如果我将 XSD 中的 maxOccurs 数字从大于 5000 的数字更改为unbounded
一切正常。可悲的是,在我的情况下这不是一个选项(我无法干预 XSD 文件)。
My question is:
我的问题是:
- Does someone know some other workaround in Xerces for this issue? Or
- Can someone recommend another XML parser that does not have this limitation?
- 有人知道 Xerces 中针对此问题的其他解决方法吗?或者
- 有人可以推荐另一个没有此限制的 XML 解析器吗?
Thanks!
谢谢!
采纳答案by mzywiol
I have found a solution that doesn't require changing the parser.
我找到了一个不需要更改解析器的解决方案。
There is a FEATURE_SECURE_PROCESSING
featurewhich puts that 5000 limitation on maxOccurs (along with several others).
有一个FEATURE_SECURE_PROCESSING
功能将 maxOccurs 限制为 5000(以及其他几个)。
And here is the document describing the limitations: http://docs.oracle.com/javase/7/docs/technotes/guides/xml/jaxp/JAXP-Compatibility_160.html#JAXP_security
这是描述限制的文档:http: //docs.oracle.com/javase/7/docs/technotes/guides/xml/jaxp/JAXP-Compatibility_160.html#JAXP_security
回答by ToSa_Bn
I had the same problem. I used this:
我有同样的问题。我用过这个:
System.setProperty("jdk.xml.maxOccurLimit", "XXXXX");
回答by Minjun Yu
I came across this thread when looking for solutions for this problem when using xjc
command in console.
xjc
在控制台中使用命令时寻找此问题的解决方案时,我遇到了这个线程。
For anyone who is using xjc
command to parse xsd, this works for me:
对于使用xjc
命令解析 xsd 的任何人,这对我有用:
$ xjc -nv foo.xsd
Be aware though:
但请注意:
By default, the XJC binding compiler performs strict validation of the source schema before processing it. Use this option to disable strict schema validation. This does not mean that the binding compiler will not perform any validation, but means that it will perform a less-strict validation.
默认情况下,XJC 绑定编译器在处理之前对源模式执行严格的验证。使用此选项可禁用严格的架构验证。这并不意味着绑定编译器不会执行任何验证,而是意味着它将执行不太严格的验证。
So if you think your xsd is from a good source, using less strict validation should not be a problem.
因此,如果您认为您的 xsd 来自一个好的来源,那么使用不太严格的验证应该不是问题。