Why not feed it to a validating parser? That should do the job! Ofcourse your XML should have reference to the DTD if it is not internal.
Most parsers support passing in the XML document as an InputSource and so
you should be fine with the whole XML being stored as a String.
Does that help?
------------------
Ajith Kallambella M. Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.