使用SAX2时如何获取Xerces-C中的Doctype声明?
我正在使用 Xerces-C 中的 SAX2 来读取 XML 文档。但是,我想检查 Doctype 声明(如果有)以确保 XML 文件采用我期望的格式。
我已经尝试了 DTDHandler 中的 unparsedEntityDecl 和 notationDecl 方法,和 EntityResolver 似乎比我的更底层我正在寻找。
我这样做的动机是能够确认输入是我期望的格式,以便我可以区分不产生输出的文档和完全错误格式的文档。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 LexicalHandler - startDTD 将为您提供 Doctype。
但是,它并不验证文档是否确实遵循该 Doctype。
您需要使用 setFeature 在阅读器中启用验证这样做。
(我只使用过 Java Xerces,但从文档来看,它看起来像方法
基本相同。 )
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. )