コード内のすべてのcom.sun.org.apache.xml.internalパッケージを削除して、安定した代替パッケージに置き換えようとしています。
これは私が置き換えた方法の1つです...
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
これは私が見つけた代替案です...
/**
* @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
ただし、生成されているxmlの違いを示しています。
作成します
<?xml version="1.0" encoding="UTF-16"?>
代わりにUTF-8を作成するためにこれをどのように変更できますか?