samedi 9 août 2014

Java - désactiver JAXB namespace substition sur gares ? -Débordement de pile


I have an XSD Schema which uses namespaces to make elements with the same name distinguishable. I am generating the JAXB bindings using the Maven plugin jaxb2-maven-plugin.


When marshalling my JAXB object, JAXB substitutes every namespace with an identifier in the root node. The XML is still valid, but the readability (or recognizability) for the user of my application suffers.


What it should look like:


<Root xmlns="http://somenamespace.com/Root">
<Config xmlns="http://somenamespace.com/ConfigTypeOne"/>
<Config xmlns="http://somenamespace.com/ConfigTypeTwo"/>
</Root>

What it looks like after marshalling:


<Root xmlns="http://somenamespace.com/Root" xmlns:ns1="http://somenamespace.com/ConfigTypeOne" xmlns:ns2="http://somenamespace.com/ConfigTypeTwo">
<ns1:Config/>
<ns2:Config/>
</Root>

Is there a way to tell JAXB to skip the substitution of namespaces and marshall the XML the way it's defined in the XSD schema?



I have an XSD Schema which uses namespaces to make elements with the same name distinguishable. I am generating the JAXB bindings using the Maven plugin jaxb2-maven-plugin.


When marshalling my JAXB object, JAXB substitutes every namespace with an identifier in the root node. The XML is still valid, but the readability (or recognizability) for the user of my application suffers.


What it should look like:


<Root xmlns="http://somenamespace.com/Root">
<Config xmlns="http://somenamespace.com/ConfigTypeOne"/>
<Config xmlns="http://somenamespace.com/ConfigTypeTwo"/>
</Root>

What it looks like after marshalling:


<Root xmlns="http://somenamespace.com/Root" xmlns:ns1="http://somenamespace.com/ConfigTypeOne" xmlns:ns2="http://somenamespace.com/ConfigTypeTwo">
<ns1:Config/>
<ns2:Config/>
</Root>

Is there a way to tell JAXB to skip the substitution of namespaces and marshall the XML the way it's defined in the XSD schema?


0 commentaires:

Enregistrer un commentaire