users@jaxb.java.net

Re: how to setup jaxb marshaller to generate the namespaces at the root node.

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Wed, 08 Jun 2005 19:37:26 -0400

Srinivasan Chikkala wrote:
> Thanks for the pointer. I actually looked at the documentation in the jwsdp1.5
> at jaxb/docs/vendorProperties.html which mentioned class
> com.sun.xml.bind.marshaller.NamespacePrefixMapper and the method
> (getPreferredPrefix ) that should be implemented for mapping namespace URIs to
> prefixes which is not sufficient for my purpose, but the way the example
> namespace-prefix override the method "getPreDeclaredNamespaceUris()" is what I
> have to do to get the namespaces at the root node, but as it mentioned in this
> method's documentation in the example, this will not be useful if I don't know
> the uris in advance and in my case, I don't know the uri's in advance as I just
> unmarshall the xml document that I receive, modify it and marshall it back to
> xml document

Maybe you can marshal it once just to collect the namespace URIs, and
then marshal it for real in the 2nd time with all the namespace decls
declared at the root?

The first time you can marshal to your own ContentHandler implementation.

When JAXB starts marshalling, it doesn't know the namespace URIs it's
going to use. So we really can't give you what you asked, unless I
traverse the whole objects. So you'll need 2 pass anyway.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com