JAXB appending unneeded namespace declarations to tags

前端 未结 1 982
孤城傲影
孤城傲影 2021-02-08 07:21

I\'m implementing a homebrew subprotocol of XMPP, and i\'m using combination of StAX and JAXB for parsing/marshalling mesages. And when I marshall a message I end up with loads

1条回答
  •  暖寄归人
    2021-02-08 07:51

    The functionality you are looking for was requested as an enhancement on the JAXB issue tracker in issue 103. The enhancement was declined, since the JAXB authors find it too expensive to traverse the object tree once more before the actual serialization starts to determine which namespaces are actually required.

    Although rather bloated, the unnecessary namespaces are not invalidating the XML document. If you really have to save the few bytes and the extra computation cost is affordable, it should be quite easy to write your own XML processor/filter, which takes the JAXB output, parses the document and writes a new document without the unused namespace definitions.

    0 讨论(0)
提交回复
热议问题