@ Override public Node insertChildAt ( Node toInsert , int index ) { if ( toInsert instanceof Element && getDocumentElement ( ) != null ) { throw new DOMException ( DOMException . HIERARCHY_REQUEST_ERR , "Only one root element allowed" ) ; } if ( toInsert instanceof DocumentType && getDoctype ( ) != null ) { throw new DOMException ( DOMException . HIERARCHY_REQUEST_ERR , "Only one DOCTYPE element allowed" ) ; } return super . insertChildAt ( toInsert , index ) ; }
Document elements may have at most one root element and at most one DTD element .