How to marshal without a namespace?

前端 未结 7 503
野的像风
野的像风 2020-12-01 06:33

I have a fairly large repetitive XML to create using JAXB. Storing the whole object in the memory then do the marshaling takes too much memory. Essentially, my XML looks lik

7条回答
  •  忘掉有多难
    2020-12-01 07:24

    The following did the trick for me:

             XMLStreamWriter writer = ...
             writer.setNamespaceContext(new NamespaceContext() {
                public Iterator getPrefixes(String namespaceURI) {
                    return null;
                }
    
                public String getPrefix(String namespaceURI) {
                    return "";
                }
    
                public String getNamespaceURI(String prefix) {
                    return null;
                }
            });
    

提交回复
热议问题