users@jaxb.java.net

Re: xmlns:ns2 and friends

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 14 Nov 2006 11:53:17 +0100

Hi.

> This is certainly a newbie question, maybe even an RTFM question, but a real
> quick look didn't reveal the answer.
>
> When I build JAXB objects that use multiple namespaces and marshal them into
> XML, the resulting XML defines namespace abbreviations like xmlns:ns2. If I
> used more namespaces, they would surely be ns3, ns4, etc. Is there any way
> to get the abbreviations to be the names I want rather than those arbitrary
> names? Thanks.

Take a look at com.sun.xml.bind.marshaller.NamespacePrefixMapper.

Implement it and provide it to the marshaller:

marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",new
NamespacePrefixMapperImpl());

Bye.
/lexi