Thursday, 15 March 2012

Remove namespace prefix while JAXB marshalling -


I have been created with JACAB objects schema while marching, XML elements are annotated with NS2. I have tried all the options available on the Net for this problem, but none of these works. I can not modify my schema or change package-info.java. After a lot of research and shuffling I finally managed to get the solution to this problem after help

Please do not post the original reference link. Sorry - there are many and I was not taking notes -. But one was definitely useful

My solution uses a filter XMLStreamWriter which applies an empty namespace reference.

  public class NoNamesWriter extends DelegatingXMLStreamWriter {private static final NamespaceContext emptyNamespaceContext = new NamespaceContext () {@Override public string getNamespaceURI (String prefix) {return "" ; } @ Override public string muffuffix (string namespaceURI) {return ""; } @ Override Public Iterator Mill Pefix (String NamespaceURI) {return tap; }}; Public Static XMLStreamWriter Filter (author author) throws XMLStreamException {new NoNamesWriter return (XMLOutputFactory.newInstance () createXMLStreamWriter (author).); } Public Nomen Water (XMLStreamWriter Writer) {Super (Author); } @ Override Public NamespaceText Millenompses Contex () {empty namespace constant; }}   

You can find a DelegatingXMLStreamWriter

You can marshalling XML filter together.

  // Filter Output to remove namespaces. Marshall (This, Nonsmount. Filler (author));   

I'm sure that I see more efficient system, but I work this one.

No comments:

Post a Comment