Question

Validation of XML with maven-created schema fails when namespace is defined, but validating against the schema works as long as I don't configure the namespace.

<transformSchemas>
<!--  doesn't work
    <transformSchema>
        <uri>tlm-classification</uri>
        <toPrefix>tlm-ec</toPrefix>
        <toFile>classification.xsd</toFile>
    </transformSchema>
-->
</transformSchemas>

If I define the namespaces, add a uri and also add the namespace to all the jaxb-annotated java classes there are two XSD files created instead of one and also the validation fails with:

src-resolve: Cannot resolve the name 'equipmentClassification' to a(n) 'type definition' component.

After I copied both xsd files into the classpath, I got

cvc-complex-type.2.4.a: Invalid content was found starting with element 'name'. One of '{"tlm-equipmentclassification":count}' is expected.

While creating the namespace-XSDs with maven I get this warning, that I couldn't fix, maybe the errors are related to that.

[INFO] --- jaxb2-maven-plugin:1.5:schemagen (default-cli) @ tlmsim ---
Note: Writing C:\dev\java\workspaces\tlm\tlmsim\schema1.xsd
Note: Writing C:\dev\java\workspaces\tlm\tlmsim\schema2.xsd
[WARNING] SimpleNamespaceResolver contained no localNamespaceURI; aborting rename.

I can also provide the xml, and the xsd files. But as the XMLs and the single non-namespace XSD validate, the errors must lie somewhere in the JAXB annotations.

Question

  • Why are there two XSD files created when I define a namespace?
  • What do I have to consider annotating the JAXB-annotated classes.
  • (Since it is suggested to use javac because schemagen will not be supported in future. Do you have any input on that?)

Additional info

I'm using org.codehaus.mojo:jaxb2-maven-plugin in version 1.5.

I have some kind of class hierarchy, and even use XmlAdapter to marshall a map thats contained in some of the XmlRootelements. Some parentclasses share the same child elements. My original plan was to automatically create a standalone scheme for each XmlRootelement in its corresponding directory.

If more information is needed, I can provide it.

No correct solution

OTHER TIPS

I have managed to get it to work by making sure the Java class annotations share the same namespace.

   <transformSchemas>
    <transformSchema>
     <uri>http://some/namespace</uri>
     <toPrefix>some</toPrefix>
     <toFile>some_schema.xsd</toFile>
    </transformSchema>
   </transformSchemas>

and all the java classes have:

@XmlRootElement(namespace ="http://some/namespace")
@XmlType(namespace ="http://some/namespace")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top