NamespaceNormalizingXMLStreamWriter implements XMLStreamWriter { @Override public void close() throws XMLStreamException { targetWriter.close(); } NamespaceNormalizingXMLStreamWriter( XMLStreamWriter targetWriter, NamespaceBindings nsBindings ); @Override void close(); @Override void flush(); @Override NamespaceContext getNamespaceContext(); @Override String getPrefix( String uri ); @Override Object getProperty( String name ); @Override void setDefaultNamespace( String uri ); @Override void setNamespaceContext( NamespaceContext context ); @Override void setPrefix( String prefix, String uri ); @Override void writeAttribute( String prefix, String namespaceURI, String localName, String value ); @Override void writeAttribute( String namespaceURI, String localName, String value ); @Override void writeAttribute( String localName, String value ); @Override void writeCData( String data ); @Override void writeCharacters( char[] text, int start, int len ); @Override void writeCharacters( String text ); @Override void writeComment( String data ); @Override void writeDTD( String dtd ); @Override void writeDefaultNamespace( String namespaceURI ); @Override void writeEmptyElement( String prefix, String localName, String namespaceURI ); @Override void writeEmptyElement( String namespaceURI, String localName ); @Override void writeEmptyElement( String localName ); @Override void writeEndDocument(); @Override void writeEndElement(); @Override void writeEntityRef( String name ); @Override void writeNamespace( String prefix, String namespaceURI ); @Override void writeProcessingInstruction( String target, String data ); @Override void writeProcessingInstruction( String target ); @Override void writeStartDocument(); @Override void writeStartDocument( String encoding, String version ); @Override void writeStartDocument( String version ); @Override void writeStartElement( String prefix, String localName, String namespaceURI ); @Override void writeStartElement( String namespaceURI, String localName ); @Override void writeStartElement( String localName );  }
@Test public void testNormalizeDefaultNamespace() throws XMLStreamException { String input = "<a xmlns=\"http: XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StringReader( input ) ); XMLStreamUtils.skipStartDocument( reader ); StringWriter output = new StringWriter(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( output ); NamespaceBindings nsBindings = new NamespaceBindings(); nsBindings.addNamespace( "app", "http: writer = new NamespaceNormalizingXMLStreamWriter( writer, nsBindings ); XMLAdapter.writeElement( writer, reader ); writer.close(); assertEquals( "<app:a xmlns:app=\"http: }
@Test public void testNormalizeNonDefaultNamespace() throws XMLStreamException { String input = "<app:a xmlns:app=\"http: XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StringReader( input ) ); XMLStreamUtils.skipStartDocument( reader ); StringWriter output = new StringWriter(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( output ); NamespaceBindings nsBindings = new NamespaceBindings(); nsBindings.addNamespace( "", "http: writer = new NamespaceNormalizingXMLStreamWriter( writer, nsBindings ); XMLAdapter.writeElement( writer, reader ); writer.close(); assertEquals( "<a xmlns=\"http: }
@Test public void testNormalizeNestedElementAndAttribute() throws XMLStreamException { String input = "<a xmlns=\"http: XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StringReader( input ) ); XMLStreamUtils.skipStartDocument( reader ); StringWriter output = new StringWriter(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( output ); NamespaceBindings nsBindings = new NamespaceBindings(); nsBindings.addNamespace( "app", "http: writer = new NamespaceNormalizingXMLStreamWriter( writer, nsBindings ); XMLAdapter.writeElement( writer, reader ); writer.close(); assertEquals( "<app:a xmlns:app=\"http: output.toString() ); }