The Source for Java Technology Collaboration

Home » java.net Forums » Java Web Services and XML » JAXP

Thread: jaxP and jaxB

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Nov 6, 2009 5:19 AM by: guilhem_legal Threads: [ Previous | Next ]
guilhem_legal

Posts: 3
jaxP and jaxB
Posted: Nov 5, 2009 9:05 AM
  Click to reply to this thread Reply

Hi,

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"?>
<root>
<firstproperty>somevalue</firstproperty>
<lagune>Canet</lagune>
<?xml version="1.0" encoding="UTF-8"?><gml:MultiGeometry xmlns:gml="http://www.opengis.net/gml"><gml:geometryMember><gml:PolyhedralSurface srsName="EPSG:27593"><gml:polygonPatches><gml:PolygonPatch><gml:exterior><gml:Ring srsName="EPSG:27593"><gml:curveMember...................</r


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

Guilhem Legal

guilhem_legal

Posts: 3
Re: jaxP and jaxB
Posted: Nov 6, 2009 5:19 AM   in response to: guilhem_legal
  Click to reply to this thread Reply

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




 XML java.net RSS