Assaf Arkin wrote: > Keith also suggested I use System.out by default, but then I'll get > people complaining of seeing stuff in the console instead of the output > file.
I don't think that people have a right to complain that they're seeing output on the console if they never set the output to where they want it! So I agree with Keith on this one. > You're prefectly right on the entity side, I'll try to get your patch in > and update the CVS. Doing some more work, I added some code to enable printing of the DOCTYPE line when serializing the DOM tree. Since the methods for determing the public and system ids on the DocumentType node aren't included until DOM Level 2 *and* DOM Level 2 is not a standard, yet, I used reflection to see if the implementation already had the appropriate methods to invoke. In this way we don't have to just pass in null to startDTD() which always has the effect of not printing the DOCTYPE line. So now that the DOCTYPE line is printing, I'm wondering why is the serializer printing entities and notations in the internal subset? In my sample, these are declared in the external DTD and should not be duplicated in the internal subset. Unfortunately, we still don't have a way of determining if entities and notations are internal or external so I'm undecided on what the default behavior in this case should be. Any thoughts? preferences? In any case, the patch for the following changes is included below. If don't mind me making changes to your serializer code directly, I'll go ahead and make future bug fixes straight in CVS. Otherwise, I'll continue posting patches. Just let me know. Change 0: Removed debugging printlns left in code. Change 1: Added ability to determine public & system ids Change 2: Removed printing of entities and notation decls in the internal subset. // BEGIN Patch Index: src/org/apache/xml/serialize/BaseMarkupSerializer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/BaseMarkupSerializer.java,v retrieving revision 1.3 diff -c -r1.3 BaseMarkupSerializer.java *** BaseMarkupSerializer.java 2000/01/14 20:40:54 1.3 --- BaseMarkupSerializer.java 2000/01/14 23:51:31 *************** *** 705,712 **** { // Only works if we're going out of DTD mode. if ( _writer == _dtdWriter ) { - System.out.println( "Writer " + _writer ); - System.out.println( "DocWriter " + _docWriter ); _line.append( _text ); _text = new StringBuffer( 20 ); flushLine( false ); --- 705,710 ---- *************** *** 776,797 **** // serialize it. docType = ( (Document) node ).getDoctype(); if ( docType != null ) { ! startDTD( docType.getName(), null, null ); ! map = docType.getEntities(); ! if ( map != null ) { ! for ( i = 0 ; i < map.getLength() ; ++i ) { ! entity = (Entity) map.item( i ); ! unparsedEntityDecl( entity.getNodeName(), entity.getPublicId(), ! entity.getSystemId(), entity.getNotationName() ); ! } ! } ! map = docType.getNotations(); ! if ( map != null ) { ! for ( i = 0 ; i < map.getLength() ; ++i ) { ! notation = (Notation) map.item( i ); ! notationDecl( notation.getNodeName(), notation.getPublicId(), notation.getSystemId() ); ! } ! } endDTD(); } // !! Fall through --- 774,803 ---- // serialize it. docType = ( (Document) node ).getDoctype(); if ( docType != null ) { ! Class docTypeClass = docType.getClass(); ! ! String docTypePublicId = null; ! String docTypeSystemId = null; ! try { ! java.lang.reflect.Method getPublicId = docTypeClass.getMethod("getPublicId", null); ! if (getPublicId.getReturnType().equals(String.class)) { ! docTypePublicId = (String)getPublicId.invoke(docType, null); ! } ! } ! catch (Exception e) { ! // ignore ! } ! try { ! java.lang.reflect.Method getSystemId = docTypeClass.getMethod("getSystemId", null); ! if (getSystemId.getReturnType().equals(String.class)) { ! docTypeSystemId = (String)getSystemId.invoke(docType, null); ! } ! } ! catch (Exception e) { ! // ignore ! } ! ! startDTD( docType.getName(), docTypePublicId, docTypeSystemId ); endDTD(); } // !! Fall through // END Patch -- Andy Clark * IBM, JTC - Silicon Valley * [EMAIL PROTECTED]