> 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.
They have no right to complain, but they will and I don't want to answer them. Throwing IllegalStateException solves that in an elegant way. > 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. I was rather hoping that people will use the OutputFormat to do that for the time being. OutputFormat will also take the system/public ids from the document type in DOM Level 2. I don't think reflection is a good way. Besides I can always cast it to the proper Xerces type as a temporary solution. > 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? Because it has no way of knowing what is external and what is internal. The DOM serializer simply dumps everything. The only solution is for the DOM serializer to not print anything, which is what I think I'll do after I get it to print correctly. > > 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. I'm fixing some stuff right now, already did 0, will do 1 and 2 and commit as soon as it's working. arkin > > // 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] -- ---------------------------------------------------------------------- Assaf Arkin www.exoffice.com CTO, Exoffice Technologies, Inc. www.exolab.org