I have generated Java classes from XSD, all works fine from a unmarshalling point of view.
However, when I marshall from JAXB classes I get the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message xmlns="http://poc.cmc.com/ScreenLayout">
<Data>
<Type>Sample</Type>
. . .
</message>
But I need
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns0:message xmlns:ns0="http://poc.cmc.com/ScreenLayout">
<ns0:Data>
<ns0:Type>Sample</ns0:Type>
. . .
how can I control that from Java?
Thanks a lot
Cant post this as a comment!
In that case the dumb application is not really consuming xml. Take a look at this link http://bdoughan.blogspot.com/2010/08/jaxb-namespaces.html and play with the namespace options. Specifically
used in a package-info.java file.
Used on a class declaration
Used on a property.
Some combination or only one of these options may give you what you want. However you should understand that you're fighting an uphill battle when you move from valid xml to xml that must contain a specific namespace prefix on all elements.
You can use the
@XmlSchema
annotation on apackage-info
class to assign a prefix to the namespace:According to XML spec both xml's are the same, as xmlns="" defines default namespace which applies to current and all child elements. XML parsers should give you the same DOM or SAX in both cases