Hello everybody.
I tried to use the the org.apache.xalan.serialize Packge to serialize a DOM to System.out. My problem is, that I can not get indention to work. More precise, indention is always one space per level, regardles of the values of 'indent' and '{http://xml.apache.org/xslt}indent-amount' of the output properties.
Could anybody please point out to me what I am missing? My environment is Xalan 2.3.1, Xerces 2.0.1, sdk1.2, Win2k.
Thanks in advance! Ralf
---- code snippet ----
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware( true );
dbf.setValidating( false );
DocumentBuilder db = null;
try { db = dbf.newDocumentBuilder(); }
catch ( ParserConfigurationException e ) {
e.printStackTrace();
System.exit( 1 );
}File xmlFile = new File( "D:\\Benutzer\\Ralf\\allinone_1.xml" ); if ( !xmlFile.canRead() ) System.exit( 1 );
Document doc = null;
try { doc = db.parse( xmlFile ); }
catch ( SAXException e ) { e.printStackTrace(); System.exit( 2 ); }
catch ( IOException e ) { e.printStackTrace(); System.exit( 3 ); }Properties outProps =
OutputProperties.getDefaultMethodProperties("xml");
outProps.setProperty( "indent", "yes" );
outProps.setProperty( "{http://xml.apache.org/xslt}indent-amount", "4" );
Serializer serializer = SerializerFactory.getSerializer( outProps );
serializer.setOutputStream( System.out );
try {
DOMSerializer ds = serializer.asDOMSerializer();
/* The following prints auf "4" as one expects. */
System.out.println( ((SerializerToXML)ds).m_indentAmount );
doc.normalize();
ds.serialize( doc );
}
catch ( IOException e ) { e.printStackTrace(); System.exit( 4 ); }----
