XMLAdapter { public static void writeElement( XMLStreamWriter writer, String namespace, String elemName, String value ) throws XMLStreamException { writer.writeStartElement( namespace, elemName ); if ( value != null ) { writer.writeCharacters( value ); } writer.writeEndElement(); } XMLAdapter();  XMLAdapter( OMElement rootElement );  XMLAdapter( URL url );  XMLAdapter( File file );  XMLAdapter( StringReader reader );  XMLAdapter( StringReader reader, String systemId );  XMLAdapter( InputStream in );  XMLAdapter( InputStream in, String systemId );  XMLAdapter( OMDocument doc, String systemId );  XMLAdapter( OMElement rootElement, String systemId );  XMLAdapter( XMLStreamReader xmlStream ); String getSystemId(); void setSystemId( String systemId ); boolean hasSchemas(); Map<String, URL> getSchemas(); void load( URL url ); void load( URL url, String httpBasicUser, String httpBasicPass ); void load( InputStream istream, String systemId ); void load( XMLStreamReader xmlStream ); void load( InputStream resourceStream ); void load( StringReader reader, String systemId ); void load( StringReader reader ); void setRootElement( OMElement rootElement ); OMElement getRootElement(); URL resolve( String url ); Object evaluateXPath( XPath xpath, Object context ); SimpleLink parseSimpleLink( OMElement element ); boolean parseBoolean( String s ); double parseDouble( String s ); float parseFloat( String s ); int parseInt( String s ); URL parseURL( String s ); QName parseQName( String s, OMElement element ); OMElement getElement( OMElement context, XPath xpath ); @SuppressWarnings("unchecked") List<OMElement> getElements( OMElement context, XPath xpath ); synchronized Object getNode( OMElement context, XPath xpath ); boolean getNodeAsBoolean( OMElement context, XPath xpath, boolean defaultValue ); double getNodeAsDouble( OMElement context, XPath xpath, double defaultValue ); float getNodeAsFloat( OMElement context, XPath xpath, float defaultValue ); BigInteger getNodeAsBigInt( OMElement context, XPath xpath, BigInteger defaultValue ); int getNodeAsInt( OMElement context, XPath xpath, int defaultValue ); URL getNodeAsURL( OMElement context, XPath xpath, URL defaultValue ); QName getNodeAsQName( OMElement context, XPath xpath, QName defaultValue ); String getNodeAsString( OMElement context, XPath xpath, String defaultValue ); Version getNodeAsVersion( OMElement context, XPath xpath, Version defaultValue ); synchronized List<?> getNodes( OMElement context, XPath xpath ); String[] getNodesAsStrings( OMElement contextNode, XPath xpath ); QName[] getNodesAsQNames( OMElement contextNode, XPath xpath ); OMElement getRequiredElement( OMElement context, XPath xpath ); List<OMElement> getRequiredElements( OMElement context, XPath xpath ); Object getRequiredNode( OMElement context, XPath xpath ); boolean getRequiredNodeAsBoolean( OMElement context, XPath xpath ); double getRequiredNodeAsDouble( OMElement context, XPath xpath ); float getRequiredNodeAsFloat( OMElement context, XPath xpath ); int getRequiredNodeAsInteger( OMElement context, XPath xpath ); URL getRequiredNodeAsURL( OMElement context, XPath xpath ); String getRequiredNodeAsString( OMElement context, XPath xpath ); QName getRequiredNodeAsQName( OMElement context, XPath xpath ); Version getRequiredNodeAsVersion( OMElement context, XPath xpath ); List getRequiredNodes( OMElement context, XPath xpath ); NamespaceBindings getNamespaceContext( OMElement element ); static void writeElement( XMLStreamWriter writer, String namespace, String elemName, String value ); static void writeElement( XMLStreamWriter writer, String namespace, String elemName, String value,
                                     String attrNS, String attribPRE, String attrName, String attrValue ); static void writeElement( XMLStreamWriter writer, String namespace, String elemName, String value,
                                     String attrNS, String attribPRE, String attrName, String attrValue,
                                     boolean writeNamespace ); static void writeOptionalAttribute( XMLStreamWriter writer, String name, String value ); static void writeOptionalNSAttribute( XMLStreamWriter writer, String namespace, String name, String value ); static void writeElement( XMLStreamWriter writer, String namespace, String elemName, String attrNS,
                                     String attrName, String attrValue ); static void writeOptionalElement( XMLStreamWriter writer, String namespace, String elemName, String value ); static void writeElement( XMLStreamWriter writer, XMLStreamReader inStream ); static void writeElement( XMLStreamWriter writer, String name, String text ); static void maybeWriteElement( XMLStreamWriter writer, String name, Object text ); static void maybeWriteElementNS( XMLStreamWriter writer, String ns, String name, Object text ); @Override String toString(); static final String DEFAULT_URL; }
@Test public void testWriteElement() throws XMLStreamException { StringWriter stringWriter = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE ); XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter( stringWriter ) ); adapter.getRootElement().serializeAndConsume( writer ); }
@Test public void testWriteElement_SimpleNamespaceBinding() throws Exception { ByteArrayOutputStream writeIn = new ByteArrayOutputStream(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( writeIn ); String xmlToWrite = "<test:me xmlns:test='http: XMLStreamReader readFrom = createReader( xmlToWrite ); XMLAdapter.writeElement( writer, readFrom ); writer.close(); assertThatXmlIsReadable( writeIn ); }
@Test public void testWriteElement_NamespaceBindingToDefaultAndPrefix() throws Exception { ByteArrayOutputStream writeIn = new ByteArrayOutputStream(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( writeIn ); String xmlToWrite = "<test:me xmlns:test='http: XMLStreamReader readFrom = createReader( xmlToWrite ); XMLAdapter.writeElement( writer, readFrom ); writer.close(); assertThatXmlIsReadable( writeIn ); }