Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control JAXB in-memory schema generation ordering/sequence?
    text
    copied!<p>I've got 3 xsd files that depend on each other to build my element definitions. Each xsd file has its own namespace. When I generate my classes using JAXB xjc, I get 3 corresponding packages. So far so good.</p> <p>My problem comes when I want to do schema validation with the unmarshaller. In order to avoid having to read in the xsd files, I generate the schemas on the fly from the class in question being unmarshalled. However, since the class depends on objects from 2 other packages, it is unable to generate the schemas unless I specify all 3 packages. Already, that isn't a very practical solution, as it requires me to know ahead of time the object hierarchy/dependency tree, and specify the package list accordingly.</p> <p>My bigger problem comes when I try to create a new schema from the 3 generated schemas using the SchemaFactory (SchemaFactory.newSchema(Source[])). Apparently, the order in which the schemas are provided to the schema factory is critical for it to resolve dependencies. If the first schema in the array depends on a type definition from the last element in the array, I get a resolve error:</p> <pre><code>org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ns1:InCalculationDataType' to a(n) 'type definition' component. </code></pre> <p>If I modify the order, and put the 3rd schema first, it succeeds without error.</p> <p>This makes it nearly impossible to write a method fairly generic, but rather have to code for each XSD case individually.</p> <p>Is there anything I can do to alleviate this problem? Is there some way to force the SchemaFactory to read everything first and only then generate its errors if it finds any? I know you can create an ErrorHandler, however the JavaDocs indicate that if it throws a Fatal error, any further processing is unreliable.</p> <p><strong>EDIT</strong></p> <p>Just for my own peace of mind, I tried to create an error handler which ignored non-fatal errors (just logged them), however the generated schema was unreliable and was unable to properly validate xml errors. Consequently, it had no value to me.</p> <p><strong>END EDIT</strong></p> <p>Any suggestions or thoughts would be appreciated.</p> <p>Thanks!</p> <p>Eric</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload