Makes sense. Assuming the declaration is at the top, is it sufficient in the case of a DTD, to check for "<!DOCTYPE root-element'? Or for a schema, to check that the path of the XML schema is in the schemaLocation attribute of the XML file root element, i.e. check for 'xsi:schemaLocation' or 'xsi:noschemalocation'?
Comment on Re^2: Quick check for XML DTD or Schema
Using one of the modules named below would work, too, but I got the sense from the OP that you don't want to do that, just a real quick peek at the file without the overhead of doing any work with it.
You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.