You can use the GO database (http://current.geneontology.org/ontology/go.obo). The namespace field for each term indicates the parent category of the term (molecular function, cellular component or biological process). Download it with wget:
See the 'is_a' field in the go.obo file. If you're looking for all subcategories of GO:0004553 ! hydrolase activity, hydrolyzing O-glycosyl compounds, you can tell awk to split the file into records by blanklines and then search for that GO term in the 'is_a' field of each record. If you need to go further, you can implement this recursively by then taking all IDs matched by the first query and using those to run a new query using the same command.