Hi

You might want to check the methods like getNamespaceContext() (probably
return an empty implementation), getPrefix(), getDefaultNamespace

By the way, it could be simpler if your writer just extends 

http://svn.apache.org/repos/asf/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamWriter.java

cheers, Sergey


Juan José Vázquez Delgado wrote:
> 
> Hi,
> 
> First of all thank you for your help.
> 
>>
>> Custom providers can also extend this method and wrap
>> the writer with yet another writer as you do, but in your specific case
>> you
>> need to register a writer using a response filter, here's an example :
>>
>> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
>>
>> you can register this filter the same way as the custom JAXB provider.
> 
> I have implemented a NoNamespacesResponseHandler getting a cleaner
> solution to my problem. Thanks.
> 
> In the other hand, my problem seems to rely on the
> CustomXmlStreamWriter I´m providing. Overwriting some methods I have
> been able to remove all prefixes in the XML but no the "xmlns"
> attributes in head elements. I´m getting something like this:
> 
> <?xml version='1.0' encoding='UTF-8'?>
> <house xmlns:ns2="http://namespace2"; xmlns="http://namespace1";>
>     <window>....</window>
>     .....
> </house>
> 
> where "window" elements don´t have any prefixes but
> xmlns:ns2="http://namespace2"; xmlns="http://namespace1"; are printed as
> attributes in "house" element.
> 
> The "NoNamespacesWriterWrapper" class is now:
> 
> class NoNamespacesWriterWrapper implements XMLStreamWriter {
> 
>         private XMLStreamWriter wrappedStreamWriter;
> 
>         public NoNamespacesWriterWrapper(XMLStreamWriter
> wrappedStreamWriter) {
>             this.wrappedStreamWriter = wrappedStreamWriter;
>         }
> 
>         public void close() throws XMLStreamException {
>             wrappedStreamWriter.close();
>         }
> 
>         public void flush() throws XMLStreamException {
>             wrappedStreamWriter.flush();
>         }
> 
>         public NamespaceContext getNamespaceContext() {
>             return wrappedStreamWriter.getNamespaceContext();
>         }
> 
>         public String getPrefix(String uri) throws XMLStreamException {
>             return wrappedStreamWriter.getPrefix(uri);
>         }
> 
>         public Object getProperty(String name) throws
> IllegalArgumentException {
>             return wrappedStreamWriter.getProperty(name);
>         }
> 
>         public void setDefaultNamespace(String uri) throws
> XMLStreamException {
>             wrappedStreamWriter.setDefaultNamespace(uri);
>         }
> 
>         public void setNamespaceContext(NamespaceContext context)
>                 throws XMLStreamException {
>             wrappedStreamWriter.setNamespaceContext(context);
>         }
> 
>         public void setPrefix(String prefix, String uri)
>                 throws XMLStreamException {
>             wrappedStreamWriter.setPrefix(prefix, uri);
>         }
> 
>         public void writeAttribute(String localName, String value)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeAttribute(localName, value);
>         }
> 
>         public void writeAttribute(String namespaceURI, String localName,
>                 String value) throws XMLStreamException {
>             writeAttribute(localName, value);
>         }
> 
>         public void writeAttribute(String prefix, String namespaceURI,
>                 String localName, String value) throws XMLStreamException
> {
>             writeAttribute(localName, value);
>         }
> 
>         public void writeCData(String data) throws XMLStreamException {
>             wrappedStreamWriter.writeCData(data);
>         }
> 
>         public void writeCharacters(String text) throws XMLStreamException
> {
>             wrappedStreamWriter.writeCharacters(text);
>         }
> 
>         public void writeCharacters(char[] text, int start, int len)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeCharacters(text, start, len);
>         }
> 
>         public void writeComment(String data) throws XMLStreamException {
>             wrappedStreamWriter.writeComment(data);
>         }
> 
>         public void writeDTD(String dtd) throws XMLStreamException {
>             wrappedStreamWriter.writeDTD(dtd);
>         }
> 
>         public void writeDefaultNamespace(String namespaceURI)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeDefaultNamespace(namespaceURI);
>         }
> 
>         public void writeEmptyElement(String localName)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeEmptyElement(localName);
>         }
> 
>         public void writeEmptyElement(String namespaceURI, String
> localName)
>                 throws XMLStreamException {
>             writeEmptyElement(localName);
>         }
> 
>         public void writeEmptyElement(String prefix, String localName,
>                 String namespaceURI) throws XMLStreamException {
>             writeEmptyElement(localName);
>         }
> 
>         public void writeEndDocument() throws XMLStreamException {
>             wrappedStreamWriter.writeEndDocument();
>         }
> 
>         public void writeEndElement() throws XMLStreamException {
>             wrappedStreamWriter.writeEndElement();
>         }
> 
>         public void writeEntityRef(String name) throws XMLStreamException
> {
>             wrappedStreamWriter.writeEntityRef(name);
>         }
> 
>         public void writeNamespace(String prefix, String namespaceURI)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeNamespace(prefix, namespaceURI);
> 
>         }
> 
>         public void writeProcessingInstruction(String target)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeProcessingInstruction(target);
>         }
> 
>         public void writeProcessingInstruction(String target, String data)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeProcessingInstruction(target, data);
>         }
> 
>         public void writeStartDocument() throws XMLStreamException {
>             wrappedStreamWriter.writeStartDocument();
>         }
> 
>         public void writeStartDocument(String version)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeStartDocument();
>         }
> 
>         public void writeStartDocument(String encoding, String version)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeStartDocument(encoding, version);
>         }
> 
>         public void writeStartElement(String localName)
>                 throws XMLStreamException {
>             wrappedStreamWriter.writeStartElement(localName);
>         }
> 
>         public void writeStartElement(String namespaceURI, String
> localName)
>                 throws XMLStreamException {
>             writeStartElement(localName);
>         }
> 
>         public void writeStartElement(String prefix, String localName,
>                 String namespaceURI) throws XMLStreamException {
>             writeStartElement(localName);
>         }
> 
>     }
> 
> Thanks and regards,
> 
> Juanjo.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Removing-XML-namespaces-and-prefixes-tp24457677p24459981.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to