Workaround for XMLSchema not supporting maxOccurs

2019-04-08 05:24发布

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!

3条回答
何必那么认真
2楼-- · 2019-04-08 05:33

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

查看更多
你好瞎i
3楼-- · 2019-04-08 05:46

I had the same problem. I used this:

System.setProperty("jdk.xml.maxOccurLimit", "XXXXX");
查看更多
疯言疯语
4楼-- · 2019-04-08 05:48

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.

查看更多
登录 后发表回答