For a larger project using XML as an export/import format, I recieved an XSD schema file. I used JAXB to generate the classes, added routines to fill the data into the generated classes. Now I am marshalling the whole file into an XML file on disk:
Spmigration mig = new Spmigration(); //Main migration object
mig.setBestellungen(new OrdersImpl().getOrders(shop));
JAXBContext jc = JAXBContext.newInstance( "my.migration.context" );
Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal( mig, new File("test.xml") );
This works like a charm. The output file is well-formed and, given the right schema, even valid. Now, I am trying to export the file, but adding the schema directly. I added a few lines:
Spmigration mig = new Spmigration(); //Main migration object
mig.setBestellungen(new OrdersImpl().getOrders(shop));
JAXBContext jc = JAXBContext.newInstance( "my.migration.context" );
Marshaller m = jc.createMarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = schemaFactory.newSchema(new File("myschema.xsd"));
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.setSchema(schema);
m.marshal( mig, new File("test.xml") );
The schema file exists and is readable (I know because I got another error when I forgot to supply the file when I first tried). Now, the line
Schema schema = schemaFactory.newSchema(new File("myschema.xsd"));
generated the following exception:
java.lang.VerifyError: (class: org/apache/xerces/impl/xs/XSAnnotationImpl, method: writeToDOM signature: (Lorg/w3c/dom/Node;S)V) Incompatible object argument for function call
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
Of course, this is not the whole stack trace. But it seems to be the problem. I’m not reading anything significant from the very low number of problems that the net knows about with this specific error message.
Is there anything I could check, anything I am doing wrong?
It’s not really a solution, but what we finally did was not add the schema using the methods described for that, but add the schema later via a textual replace in another step.