Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for XMLSchema not supporting maxOccurs larger than 5000

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!

like image 343
mzywiol Avatar asked May 20 '13 13:05

mzywiol


3 Answers

I had the same problem. I used this:

System.setProperty("jdk.xml.maxOccurLimit", "XXXXX");
like image 57
ToSa_Bn Avatar answered Nov 19 '22 05:11

ToSa_Bn


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

like image 22
mzywiol Avatar answered Nov 19 '22 06:11

mzywiol


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.

like image 6
Minjun Yu Avatar answered Nov 19 '22 05:11

Minjun Yu