Workaround for XMLSchema not supporting maxOccurs larger than 5000

大憨熊 提交于 2019-12-21 12:59:02

问题


My problem is with parsing an XSD Schema that has elements with maxOccurs larger than 5000 (but not unbounded).

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

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 option in my case (I cannot meddle with the XSD file).

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?

Thanks!


回答1:


I had the same problem. I used this:

System.setProperty("jdk.xml.maxOccurLimit", "XXXXX");



回答2:


I have found a solution that doesn't require changing the parser.

There is a FEATURE_SECURE_PROCESSING feature which puts that 5000 limitation on maxOccurs (along with several others).

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




回答3:


I came across this thread when looking for solutions for this problem when using xjc command in console.

For anyone who is using xjc command to parse xsd, this works for me:

$ 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.

So if you think your xsd is from a good source, using less strict validation should not be a problem.



来源:https://stackoverflow.com/questions/16651005/workaround-for-xmlschema-not-supporting-maxoccurs-larger-than-5000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!