programmatically validate xml against DTD

I am trying to build a service to validate an xml file against a DTD. Ideally the service would accept two input filenames (xml file, DTD file) and return a valid/invalid result.

This can be easily done if I convert the DTD to a record/schema manually using the Developer, but I want to do the whole job in a service.

I got the job done by using the unexposed service generateFromDTDString, which creates a schema from a DTD. It works fine but I would like the service to get rid of the generated schema.

Any ideas how to delete a schema from within a flow step?

I found the answer to my own question.