0

Currently i have created Java classes from a large number of schema files (.xsd). The resulting classes are working (generated via jaxb2-maven-plugin). But now i try to generate an XML out of a object structure. The first thing is which i not fully understand why i need to give all namespaces which are available during the creation of a JAXB context?

String[] context = { "Namespace1", "Namespace2", ...};

JAXBContext jc = JAXBContext.newInstance(Joiner.on(":").join(context));

via a marshaller i can generate an XML document, but the problem i have is the following:

<StartTag xmlns="Basenamespace" xmlns:ns1="Namespace1" xmlns:ns2="Namespace2" ...>
   <...>
     <ns1:T1>...</ns1:T1>
     <ns2:TX>...</ns2:TX>
     ...
</StartTag>

I would like to have generated something like this:

<StartTag xmlns="Basenamespace">
   <...>
     <T1 xmlns="Namespace1">
     ...
     </T1>

     <TX xmlns="Namespace2">
      ...
     </TX>
     ...
</StartTag>

So the question is: Is that achievable via properties in JAXB ? Furthermore is it possible to influence at which tag the xmlns elements will be created or not?

skaffman
  • 398,947
  • 96
  • 818
  • 769
khmarbaise
  • 92,914
  • 28
  • 189
  • 235

1 Answers1

0

It looks like i don't have luck about that problem. I've found the following:

jaxb namespaces in each element instead of root element during marshalling

Community
  • 1
  • 1
khmarbaise
  • 92,914
  • 28
  • 189
  • 235