1

I have developed an ATOM feed using the eclipse IDE. The ATOM feed is based on the org.apache.wink.common.model.atom.AtomFeed. The xml content is generated using JAXB. Everything works correctly; however, I need to add a processing instruction to the atom feed and it appears that there is no exposed method available that allows me to do this.

The first line in the xml is the standard

<?xml version="1.0......etc>

I need to add an additional

<?bla bla ?>

instruction after this entry.

I need some way to insert this instruction before returning the feed. There is an unmarshal method that is available and I was wondering if I could somehow unmarshal the feed, add the processing instruction and then marshal the feed back for the return object. This seems like a hack but I've run out of ideas!

I've searched everywhere and I just can't seem to locate any solid examples showing how this can be achieved. Any help/alternatives would be greatly appreciated.

Mike
  • 21
  • 2

1 Answers1

0

You can create an XMLStreamWriter then use it to write the processing instruction and then marshal your objects to this XMLStreamWriter. When you marshal to a document that has already been started you need to set the following property on your Marshaller.

    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

UPDATE

Thanks for the quick response... The feed is returned and automatically handled by the framework. i.e. @GET @Produces(MediaType.APPLICATION_ATOM_XML) //@Produces(MediaType.APPLICATION_XML) @Path(value="{pnref}") public AtomFeed doInquiry(@PathParam(value="pnref") String pnref,

You can implement a MessageBodyWriter that leverages JAXB and adds the processing instruction.

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • The feed is returned and handled by the framework. i.e.. @GET @Produces(MediaType.APPLICATION_ATOM_XML) //@Produces(MediaType.APPLICATION_XML) @Path(value="{pnref}") public AtomFeed doInquiry(@PathParam(value="pnref") String pnref, and the response object is an AtomFeed object. Do you have an snippets of code that I can use as an example? Thanks again for the quick response. – Mike Nov 14 '13 at 20:05