开发者

How to get the Doctype Declaration in Xerces-C when using SAX2?

开发者 https://www.devze.com 2022-12-29 22:26 出处:网络
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 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开发者_如何学C 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号