Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 27 other followers

  • Archives

  • Categories

  • Stats

    • 265,009
  • Live Traffic

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

Posted by Jai on June 6, 2008

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 :

build Script entry:

***********
<goal name=”gen-test” description=”Generate XMLBeans for test XSD” prereqs=”init-gen”>
<ant:xmlbean destfile=”${basedir}/target/test-1.0.jar” failonerror=”true” download=”true” noupa=”true”>
<classpath refid=”maven.dependency.classpath” />
<fileset dir=”./src/resources/xsd”>
<include name=”test-1.0.xsd*” />
</fileset>
</ant:xmlbean>
<ant:echo>blah blah….</ant:echo>
</goal>
************

Get the XmlObject (<XmlObject&gt.Factory.parse()) and avoid any UPA rule violation exception.

2. Set UPA off while creating Schema from XSD:

Lets say I need to implement this condition in my xsd schema. I want the sequence to be more flexible, keeping the explicit members there, the user should be able to add any extra nodes also.

XSD entry (test.xsd):

***************
…..
<xsd:sequence>
<xsd:element name=”test1″ minOccurs=”0″/>
<xsd:element name=”test2″ minOccurs=”0″/>
<xsd:any processContents=”skip” minOccurs=”0″ maxOccurs=”unbounded”/>
</xsd:sequence>
….
***************

While generating the Schema from this resource like

javax.xml.validation.SchemaFactory schemaFactory = javax.xml.validation.SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Schema schema = schemaFactory.newSchema(<resource:test.xsd>);

it throws exception:

***************
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:

schemaFactory.setFeature(“http://apache.org/xml/features/validation/schema-full-checking “, false);

[ true : Enable full schema grammar constraint checking, including checking which may be time-consuming or memory intensive. Currently, unique particle attribution constraint checking and particle derivation restriction checking are controlled by this option. ]

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.

I hope this would be of some help.

About these ads

3 Responses to “How to set UPA (Unique Particle Attribution) rule violation off?”

  1. Jai said

    This is how it looks for which implementation of SchemaFactory to use on new instance :

    http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html#newInstance(java.lang.String)

  2. Dinesh Kumar Mamotra said

    thanks dear, i was facing same problem from last night, but now from your help i am able to solve my issue.

  3. Draxis said

    Great info! I was facing the same problem this last 3 days, but thanks to your info I’ve solve it! TNX a lot!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: