JAXB, how to marshal without a namespace
Posted
by Alvin
on Stack Overflow
See other posts from Stack Overflow
or by Alvin
Published on 2010-05-12T05:02:58Z
Indexed on
2010/05/12
5:14 UTC
Read the original article
Hit count: 257
I have a fairly large repetitive XML to create using JAXB. Storing the whole object in the memory then do the marshaling takes too much memory. Essentially, my XML looks like this:
<Store>
<item />
<item />
<item />
.....
</Store>
Currently my solution to the problem is to "hard code" the root tag to an output stream, and marshal each of the repetitive element one by one:
aOutputStream.write("<?xml version="1.0"?>")
aOutputStream.write("<Store>")
foreach items as item
aMarshaller.marshall(item, aOutputStream)
end
aOutputStream.write("</Store>")
aOutputStream.close()
Somehow the JAXB generate the XML like this
<Store xmlns="http://stackoverflow.com">
<item xmlns="http://stackoverflow.com"/>
<item xmlns="http://stackoverflow.com"/>
<item xmlns="http://stackoverflow.com"/>
.....
</Store>
Although this is a valid XML, but it just look ugly, so I'm wonder is there any way to tell the marshaller not to put namespace for the item elements? Or is there better way to use JAXB to serialize to XML chunk by chunk?
© Stack Overflow or respective owner