converting topdocument to a parsing function