从 Xerces 获取架构数据类型
我在 Xerces C++ 中使用 SAX2,并且希望在处理元素时获取 XML 架构数据,以便了解架构中定义的类型。我怎样才能做到这一点?
I am using SAX2 in Xerces C++ and would like to get XML Schema data while I handle elements so that I know their type defined in the Schema. How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我知道该怎么做了。关于该主题的可用文档很少。显然,我需要将 XMLReaderFactory::createXMLReader() 返回的 SAX2XMLReader 转换为 SAX2XMLReaderImpl。然后我可以在该接口上注册 PSVIHandler 实现。我必须提供我自己的 PSVIHandler 实现,因为我无法在 Xerces 中找到默认实现。
一旦 PSVI 的实现注册到 SAX2XMLReaderImpl,我就会创建一个 ContentHandler impl 并将 PSVI 处理程序 impl 传递给其构造函数。然后我向 SAX2XMLReaderImpl 注册 ContentHandler。然后,当我解析时,我可以从 PSVIHandler 访问信息以获取架构相关信息。
这一切看起来都很笨拙,而且 PSVIHandler 界面看起来很不友好。也许有更好的方法。
这是一个代码片段:
Okay, I figured out how to do this. Sparse documentation available on the subject. Apparently I need to cast the SAX2XMLReader that XMLReaderFactory::createXMLReader() returns, to a SAX2XMLReaderImpl. Then I can register an PSVIHandler implementation on that interface. I have to provide my own implementation of the PSVIHandler, as I could not find a default implementation within Xerces.
Once this implementation of PSVI is registered with the SAX2XMLReaderImpl, I then create an ContentHandler impl and pass the PSVI handler impl to its constructor. Then I register the ContentHandler with SAX2XMLReaderImpl. Then when I am parsing I can access information from PSVIHandler to get schema related info.
It all seems very clumsy and the PSVIHandler interface seems very unfriendly. Maybe there is a better way.
Here is a code snippet: