question: public void write ( Node node ) { if ( node == null ) { return ; } short type = node . getNodeType ( ) ; switch ( type ) { case Node . DOCUMENT_NODE : { Document document = ( Document ) node ; fXML11 = false ; if ( ! fCanonical ) { if ( fXML11 ) { fOut . print ( "<?xml version=\"1.1\" encoding=\"UTF-8\"?>" ) ; } else { fOut . print ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ) ; } fOut . print ( "\n" ) ; fOut . flush ( ) ; write ( document . getDoctype ( ) ) ; } write ( document . getDocumentElement ( ) ) ; break ; } case Node . DOCUMENT_TYPE_NODE : { DocumentType doctype = ( DocumentType ) node ; fOut . print ( "<!DOCTYPE " ) ; fOut . print ( doctype . getName ( ) ) ; String publicId = doctype . getPublicId ( ) ; String systemId = doctype . getSystemId ( ) ; if ( publicId != null ) { fOut . print ( " PUBLIC '" ) ; fOut . print ( publicId ) ; fOut . print ( "' '" ) ; fOut . print ( systemId ) ; fOut . print ( '\'' ) ; } else if ( systemId != null ) { fOut . print ( " SYSTEM '" ) ; fOut . print ( systemId ) ; fOut . print ( '\'' ) ; } String internalSubset = doctype . getInternalSubset ( ) ; if ( internalSubset != null ) { fOut . println ( " [" ) ; fOut . print ( internalSubset ) ; fOut . print ( ']' ) ; } fOut . println ( '>' ) ; break ; } case Node . ELEMENT_NODE : { fOut . print ( '<' ) ; fOut . print ( node . getNodeName ( ) ) ; Attr [ ] attrs = sortAttributes ( node . getAttributes ( ) ) ; for ( int i = 0 ; i < attrs . length ; i ++ ) { Attr attr = attrs [ i ] ; fOut . print ( ' ' ) ; fOut . print ( attr . getNodeName ( ) ) ; fOut . print ( "=\"" ) ; normalizeAndPrint ( attr . getNodeValue ( ) , true ) ; fOut . print ( '"' ) ; } fOut . print ( '>' ) ; fOut . flush ( ) ; Node child = node . getFirstChild ( ) ; while ( child != null ) { write ( child ) ; child = child . getNextSibling ( ) ; } break ; } case Node . ENTITY_REFERENCE_NODE : { if ( fCanonical ) { Node child = node . getFirstChild ( ) ; while ( child != null ) { write ( child ) ; child = child . getNextSibling ( ) ; } } else { fOut . print ( '&' ) ; fOut . print ( node . getNodeName ( ) ) ; fOut . print ( ';' ) ; fOut . flush ( ) ; } break ; } case Node . CDATA_SECTION_NODE : { if ( fCanonical ) { normalizeAndPrint ( node . getNodeValue ( ) , false ) ; } else { fOut . print ( "<![CDATA[" ) ; fOut . print ( node . getNodeValue ( ) ) ; fOut . print ( "]]>" ) ; } fOut . flush ( ) ; break ; } case Node . TEXT_NODE : { normalizeAndPrint ( node . getNodeValue ( ) , false ) ; fOut . flush ( ) ; break ; } case Node . PROCESSING_INSTRUCTION_NODE : { fOut . print ( "<?" ) ; fOut . print ( node . getNodeName ( ) ) ; String data = node . getNodeValue ( ) ; if ( data != null && data . length ( ) > 0 ) { fOut . print ( ' ' ) ; fOut . print ( data ) ; } fOut . print ( "?>" ) ; fOut . flush ( ) ; break ; } case Node . COMMENT_NODE : { if ( ! fCanonical ) { fOut . print ( "<!--" ) ; String comment = node . getNodeValue ( ) ; if ( comment != null && comment . length ( ) > 0 ) { fOut . print ( comment ) ; } fOut . print ( "-->" ) ; fOut . flush ( ) ; } } } if ( type == Node . ELEMENT_NODE ) { fOut . print ( "</" ) ; fOut . print ( node . getNodeName ( ) ) ; fOut . print ( '>' ) ; fOut . flush ( ) ; } }
target:  Writes the specified node, recursively.