I have been trying to get rid of all com.sun.org.apache.xml.internal packages in my code replacing them with stable alternatives.
This is one method I've replaced...
import com.sun.org.apache.xml.internal.serialize.LineSeparator;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
...
...
/**
* @param source
* @param target
* @throws IOException
*/
protected static void serialize( Document source, Writer target ) throws IOException
{
OutputFormat outputFormat = new OutputFormat( (Document) source );
outputFormat.setLineSeparator( LineSeparator.Windows );
// format.setIndenting(true);
outputFormat.setLineWidth( 0 );
outputFormat.setPreserveSpace( true );
XMLSerializer serializer = new XMLSerializer( target, outputFormat );
serializer.asDOMSerializer();
serializer.serialize( source );
} // end serialize
this is an alternative I found...
/**
* @param source
* @param target
* @throws IOException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
* @throws ClassCastException
*/
protected static void serialize( Document source, Writer target ) throws Exception
{
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation( "LS" );
LSSerializer writer = impl.createLSSerializer();
target.write( writer.writeToString(source) );
} // end serialize
However, its showing a difference in the xml that is being produced.
It creates
<?xml version="1.0" encoding="UTF-16"?>
How can this be modified to create UTF-8 instead?