Artem
Artem

Reputation: 505

Jaxb marshal different namespaces with recursive one

I want to marshal into xml like this:

<?xml version='1.0' encoding='UTF-8'?>
<ns1:rootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="some_location" xmlns:ns1="namespace1"
      xmlns:ns2="namespace2">
  <ns1:firstElement>some text</ns1:firstElement>
  <ns1:secondElement>
    <ns2:otherElement>some text</ns2:otherElement>
    ...
    <ns2:nElement>
      <ns2:innerElement>
        <ns2:otherInnerElement>some text</ns2:otherInnerElement>
      </ns2:innerElement>
    </ns2:nElement>
  </ns1:secondElement>
</ns1:rootElement>

There are 2 namespaces. The first one is only for rootElement and direct root element. The second namespace is for other huge number of elements with recursion.

How can I describe this without annotating each elements (tags) for namespace2?

Upvotes: 0

Views: 272

Answers (1)

Artem
Artem

Reputation: 505

I put root class in one package with package-info like that:

@XmlSchema(
    namespace = "namespace1",
    elementFormDefault = XmlNsForm.QUALIFIED,
    xmlns = {
        @XmlNs(prefix = "ns1", namespaceURI = "namespace1")
    }
)

And other classes I put in another package with own package-info:

@XmlSchema(
    namespace = "namespace2",
    elementFormDefault = XmlNsForm.QUALIFIED,
    xmlns = {
        @XmlNs(prefix = "ns2", namespaceURI = "namespace2")
    }
)

Upvotes: 0

Related Questions