tags:

views:

32

answers:

1

I am using SAX2 from Xerces-C to read an XML document. However, I would like to check the Doctype declaration (if there is any) to make sure that the XML file is in the format I am expecting.

I have tried the unparsedEntityDecl and notationDecl methods from the DTDHandler, and EntityResolver seems to be more low-level than what I am looking for.

My motivation is for this is to be able to confirm that the input is of the format I am expecting so that I can differentiate between documents which produce no output and those that are entirely of the wrong format.

+1  A: 

Look at LexicalHandler - startDTD will get you the Doctype. However, it does not validate that the document actually follows that Doctype. You need to enable validation in the reader with setFeature to do that. ( I've only used Java Xerces, but from the docs, it looks like the methods are basically the same. )

Steven D. Majewski
Thanks! This worked once I remembered/realised to "register" my Handler using the SAX2XMLReader::setLexicalHandler() method as well as just implementing it.
ArtB