private static void copyHeader ( final Document doc , final Document ndoc ) { NodeList headnl = doc . getElementsByTagName ( "head" ) ; if ( headnl . getLength ( ) > 0 ) { Element head = ( Element ) headnl . item ( 0 ) ; ndoc . getDocumentElement ( ) . insertBefore ( ndoc . adoptNode ( head . cloneNode ( true ) ) , ndoc . getDocumentElement ( ) . getFirstChild ( ) ) ; } // end if }
Copy the html header from doc to ndoc