Question

I am using several different schemas in my project. They are each compiled into a separate jar, each using a separate package, using the xmlbeans ant task. I can only seem to successfully parse xml (using the .Factory.parse(String xml) method) for the schema jar that is first in the classpath, otherwise I get a ClassCastException as described in this bug. If I change the jar ordering, a different schema will be able to parse successfully, and the ClassCastException will be thrown for a different class.

I've done some debugging, and I'm coming to the conclusion that the structure of the schemaorg_apache_xmlbeans.namespace package is probably responsible. Since my schemas do not have namespaces, each of jars I've built share some files that are identically named in identical packages. Specifically, I've seen that each jar has a schemaorg_apache_xmlbeans.namespace._nons.xmlns.xsb file that seems to point to the actual schema for that jar. If the factory uses this file to determine some of the classes it will use to parse the xml it has, this may explain the ClassCastException, as it's only looking at the first file on the classpath and not the correct one for the XML it has. Whether there is any option to specify the namespaces for the schemas generated (like java namespaces) in the wsdls or xsds or in the ant task "wsdl to java" compilation?

Was it helpful?

Solution

I think the problem is that XMLBeans uses some kind of internal schema cache that mixes them up.

Have you tried giving your schemas (xsds) different namespaces?

OTHER TIPS

This can be resolved by using the XMLOptions argument to the parse method. Example: XmlOptions opts = new XmlOptions(); opts.setDocumentType(YourDocument.Factory.newInstance().schemaType()); YourDocument.parse(String xml, opts);

see xmloptions.setDocumentType

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top