Skip to main content

jaxP and jaxB

1 reply [Last post]
Joined: 2007-12-06


I use an XML writer based on a XMLEventWriter.

For some part of my xml i want to use JAXB to marshall an object into my XMLEventWriter.

The Marshaller of JAXB has the capability to do that :

eventWriter.add(new StartDocumentEvent("UTF-8"));
eventWriter.add(new CharacterEvent("\n"));
eventWriter.add(new StartElementEvent("root"));

eventWriter.add(new StartElementEvent("firstproperty"));
eventWriter.add(new CharacterEvent("somevalue"));
eventWriter.add(new EndElementEvent("firstproperty"));

Marshaller m = pool.acquireMarshaller();
m.marshal(myobjectToMarshall, eventWriter);

The problem is that :
- first i've got a second xmlHeader beginning at the node of my JAXB marshall
- second : i lost the pretty print of JAXB (i can survive that but ...)

example of the created xml:

<?xml version="1.0" encoding="UTF-8"?>

<?xml version="1.0" encoding="UTF-8"?>

Is someone now a solution to at least remove the second XML header (properly)

Guilhem Legal

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-12-06

I reply to myself, to remove the xml header in the JAXB marshalled you have to add a property to the JAXB marshaller :

marshaller.setProperty(marshaller.JAXB_FRAGMENT, true);

I still looking for the pretty print part