0

I am trying to create an XML representation of objects without the namespace prefixes using JAXB. I would like to have my objects marshalled to look similar to the following:

<test xmlns="namespace1">
    <field1>
        <field2 xmlns="namespace2">
            ...
        </field2>
    </field1>
</test>

Unfortunately, I need it formatted this way rather than using prefixes and a root declaration of the namespaces because the server I am connecting to refuses any other formats. I have tried several different things to get JAXB to marshal my objects this way, but I haven't had any success. Is this possible with JAXB?

EDIT: I am not trying to remove all namespace declarations. I at least need a namespace declaration on the child element with no prefixes in order for this to work.

LucasP
  • 1,665
  • 16
  • 24
  • Not a duplicate - that question removes all namespace information completely, whereas this one wants to preserve the namespace URIs but apply them using default `xmlns=...` declarations at different levels instead of prefixes. – Ian Roberts Sep 08 '15 at 16:48
  • I have a feeling the best way to achieve this is to pass a [JAXBSource](http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/util/JAXBSource.html) to an [XSL transformation](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/Transformer.html). – VGR Sep 09 '15 at 13:36
  • @VGR Thanks for your help. That may be an option. I hope that I won't have to manually create the objects. – LucasP Sep 09 '15 at 14:10

0 Answers0