public Document normalise ( ) { Element htmlEl = findFirstElementByTagName ( "html" , this ) ; if ( htmlEl == null ) htmlEl = appendElement ( "html" ) ; if ( head ( ) == null ) htmlEl . prependElement ( "head" ) ; if ( body ( ) == null ) htmlEl . appendElement ( "body" ) ; // pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care // of. do in inverse order to maintain text order. normaliseTextNodes ( head ( ) ) ; normaliseTextNodes ( htmlEl ) ; normaliseTextNodes ( this ) ; normaliseStructure ( "head" , htmlEl ) ; normaliseStructure ( "body" , htmlEl ) ; ensureMetaCharsetElement ( ) ; return this ; }
Normalise the document . This happens after the parse phase so generally does not need to be called . Moves any text content that is not in the body element into the body .