Marshaller not writing namespace information

View: New views
2 Messages — Rating Filter:   Alert me  

Marshaller not writing namespace information

by Tonio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a really big problem, I'm constructing an xml from Java Mapped Classes and no information about namespace is written to the output, so the result is not a well-written XML just some nicely formatted string :-).

I'm using jvm 1.6.0_05 with whatever JAXB version it has.

I have my Mapped Classes in a jar file, each package has his own package-info.java with the XmlSchema tag defined, NO ObjectFactory. Basically my application does something like:

------------------------------------------------------------------------------------------------------
Code Snippet
------------------------------------------------------------------------------------------------------
package test.xml;

import biz.Policy; // mapped classes with their own namespace in package-info.java

public class Execute {

    public void writeXml(Policy pol) throws Exception {
       JAXBContext ctx=JAXBContext.newInstance(Envelope.class);

       Envelope envelope=new Envelope();
       envelope.policy = pol;

       Marshaller mm = ctx.createMarshaller();
       mm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

       mm.marshall(envelope, {output});
    }

    @XmlRootElement(namespace="http://www.xxx.org/xsd/test-cases")
    public static class Envelope {

        @XmlElement
        @XmlElementWrapper(name="list")
        public Policy policy;
    }

}

------------------------------------------------------------------------------------------------------
Resulting xml (sorry for the [])
------------------------------------------------------------------------------------------------------
[ns2:envelope xmlns:ns2="http://www.xxx.org/xsd/test-cases"]
[list] [!-- no namespace prefix here !!!!! --] 
    [policy] [!-- no namespace !!!!! --] 
        ........policy data...........
    [/policy]
[/list]
[/ns2:envelope]

If I generate the schemas for my envelope class, all things seems well written, so I'm a bit lost of what is happening.

Some clue of what I'm missing that makes JAXB miss the policy and list namespace in my resulting XML ?

Thanks in advance tonio


Re: Marshaller not writing namespace information

by Tonio :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry this is MY MISTAKE.

I'm still getting confused between "xsi:type" and element.

In my example although policy is defined in its namespace, element
policy inside the message element is not defined
in any namespace yet.

So everything is OK.

Thanks to everybody that simply bother himself to read this message
tonio

Tonio wrote:
Hi,

<p>I have a really big problem, I'm constructing an xml from Java Mapped Classes
and no information about namespace is written to the output, so the result is
not a well-written XML just some nicely formatted string :-).

<p>I'm using jvm 1.6.0_05 with whatever JAXB version it has.

<p>I have my Mapped Classes in a jar file, each package has his own
package-info.java with the XmlSchema tag defined, NO ObjectFactory.

Basically my application does something like:

<pre>
------------------------------------------------------------------------------------------------------
Code Snippet
------------------------------------------------------------------------------------------------------
package test.xml;

import biz.Policy; // mapped classes with their own namespace in package-info.java

public class Execute {

    public void writeXml(Policy pol) throws Exception {
       JAXBContext ctx=JAXBContext.newInstance(Envelope.class);

       Envelope envelope=new Envelope();
       envelope.policy = pol;

       Marshaller mm = ctx.createMarshaller();
       mm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

       mm.marshall(envelope, {output});
    }

    @XmlRootElement(namespace="http://www.xxx.org/xsd/test-cases")
    public static class Envelope {

        @XmlElement
        @XmlElementWrapper(name="list")
        public Policy policy;
    }

}

------------------------------------------------------------------------------------------------------
Resulting xml (sorry for the [])
------------------------------------------------------------------------------------------------------
[ns2:envelope xmlns:ns2="http://www.xxx.org/xsd/test-cases"]
[list] [!-- no namespace prefix here !!!!! --]
    [policy] [!-- no namespace !!!!! --]
        ........policy data...........
    [/policy]
[/list]
[/ns2:envelope]

</pre <p>If I generate the schemas for my envelope class, all things
seems well written, so I'm a bit lost of what is happening.

<p>Some clue of what I'm missing that makes JAXB
miss the policy and list namespace in my resulting XML ?

<p>Thanks in advance
tonio
LightInTheBox - Buy quality products at wholesale price!