users@jaxb.java.net

Re: enveloping an XML node inside another XML node

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 30 Mar 2007 12:10:17 -0700

Carlos Gonzalez-Cadenas wrote:
> Hi all,
>
> For a concrete project, I have to envelope a XML signature (a ds:Signature)
> as a child node of another node (that belongs to a container of a transport
> protocol). I parse the XML Signature (that has its own namespace
> declarations) from a file, unmarshal to JAXB and use the setter methods of
> the parent container to set the XML Signature as a child.
>
> The problem is that the marshaller rewrites all the namespace prefixes and
> namespace declarations, changing the prefixes and moving the namespace nodes
> to the root element of the combined document. As you can imagine, this
> renders the XML Signature unusable.

You should first get your signature converted into the proper DOM nodes,
then attach that as a child.

When JAXB marshals a DOM tree as sub-elements, it preserves all the
namespace declarations.

Since XML signature is very sensitive to the slightest change in the
infoset, binding XMLDsig schema to JAXB for the purpose of producing a
signature is a bad idea.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com