xs:anyType issue – ElementNSImpl Vs Node

XSD is having element like this

<xs:element name="companyname" type="xs:anyType" minOccurs="0"/>

JAXB Generated Class is having code like this

protected Object companyname;

To fetch the data we are using

final ElementNSImpl element = (ElementNSImpl)atGiven;

To resolve this element we can use either of this.

If we use this import, it is working in Eclipse. But failing in osgi.
import org.apache.xerces.dom.ElementNSImpl;
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to org.apache.xerces.dom.ElementNSImpl

If we use this import, paxrunner with Equinox is failing to do boot delegation com.sun.*
import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;

We have two solutions:

replace xs:anyType to xs:string if permits.
or

Make sure that boot delegation works.

Final Solution:
It is better not to use code specific to implementation.
It is better to use interface. Due to this used Node and resolved the issue.
import org.w3c.dom.Node;

-o-

Advertisements

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