Question

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.

Was it helpful?

Solution

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. )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top