Fixed issue when doctype is not document's first child

This matches implementation both Firefox & WebKit.