From the responses in this thread I understand that having control over the
namespace declarations produced by the Marshaller is an issue for many
people which is not addressed by the JAXB API so far.
Currently I have also implemented a SAX filter for this purpose. However, I
would really prefer a simple way to customize the marshalling process. Is
there any chance that this will be a feature of upcoming JAXB versions?
Von: Colin Fleming [mailto:colin.mailinglist@...]
Gesendet: Dienstag, 18. November 2008 13:01
An: users@... Cc: claus.nagel@... Betreff: Re: Duplicated namespace declaration from output xml
Sorry for the late response, I just saw this.
For a slightly less foul solution, consider marshalling through a
TransformerHandler, and using SAX to filter the namespace events you don't
want. It's still pretty ugly, but it works for us.
2008/10/22 Wolfgang Laun <wolfgang.laun@...>
I'm aware that I'm suggesting a terrible hack, wrought with ifs and buts, so
don't tell me.
To effect certain local modifications on the marshalled text you could do
Call marshal with a PipedOutputStream pos as its second parameter. Connect a
PipedInputStream pis to that and start a thread reading from pis,
accumulating characters into a StringBuffer. At certain positions (e.g.at
line ends, after requesting JAXB_FORMATTED_OUTPUT) delete strings such as
xmlns:xs="..." from the StringBuffer and emit the StringBuffer to the
ultimate destination for your marhalled text. Insert is, of course, possible
as well, assuming you can identify the position.
I think the problem comes from the xs:anySimpleType. If I change it to
string, it will works as normal. It also make sense that jaxb create output
with types for anySimpleType element. However, it will be a lot nicer if
jaxb can group all the xml declaration on the top and just use the nametag
for it. Do you know a way to tell jaxb to do that?
Attachment is the complete project for you to run.