How to set UPA (Unique Particle Attribution) rule violation off?

XML Schema developer are very well aware of UPA (Unique Particle Attribution) rule violation and a lot of times might have faced this requirement to set it off. Here I will try to put it in simple words to set UPA violation off. For those who want to have a look at what UPA problem is all about I would suggest to go through this article UPA in plain English by Priya Lakshminarayanan.

1. Set UPA off while generating xml beans:

To get rid of UPA violation, set “noupa” to true while generating xml beans.

Lets say we have the following goal entry gen-test in the build script for generating xml beans for test-1.0.xsd :

***************org.xml.sax.SAXParseException: cos-nonambig: “http://www.test.com/test“:test1 and WC[##any] (or elements from their substitution group) violate “Unique Particle Attribution”. During validation against this schema, ambiguity would be created for those two particles.at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)at com.sun.org.apache.xerces.internal.impl.xs.XSConstraints.reportSchemaError(XSConstraints.java:315)at com.sun.org.apache.xerces.internal.impl.xs.XSConstraints.fullSchemaChecking(XSConstraints.java:463)at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:530)at com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl.newSchema(SchemaFactoryImpl.java:206)
….
****************

we know the problem, XSConstraints throws XMLSchemaException exception while doing fullSchemaChecking. To set the full schema checking off we can use something like:

But the problem is that not every implementation of SchemaFactory allows you to set this violation ON/OFF.

The com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl doesn’t allow you to set this feature but org.apache.xerces.jaxp.validation.XMLSchemaFactory allows you to set this violation rule to true/false.