从 Xerces 获取 XML 数据 (c++)
我是 XML 的后来者 - 必须解析 XML 文件。 我们公司已经在使用 xerces,所以我设法拼凑了一个示例应用程序 (SAX),它显示文件中的所有数据。 但是,解析完成后,我希望能够调用解析器或具有文件内部表示的其他实体并迭代字段/数据。
基本上我希望能够传递一些键或其他字符串并返回字符串或键/值对的集合。 我不这么认为。 对我来说,这显然是一件好事。 我错过了什么吗?
DOM 解析是我想要的,还是也达不到要求?
I am a latecomer to XML - have to parse an XML file. Our company is using xerces already so I managed to cobble together a sample app (SAX) that displays all the data in a file. However, after parsing is complete I was expecting to be able to call the parser or some other entity that had an internal representation of the file and iterate through the fields/data.
Basically I want to be able to hand it some key or other string(s) and get back strings or collections of key/value pairs. I do not see that. It seems pretty obvious to me that that is a good thing to do. Am I missing something?
Is the DOM parsing what I want, or does that fall short too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Xerces 提供 SAX 和 DOM 处理。 SAX 解析不构造模型,因此解析完成后,无需检查或迭代任何内容。 DOM 处理生成一个树形结构模型,它可以满足您的需求。
Xerces provides both SAX and DOM processing. SAX parsing doesn't construct a model, so once parsing is finished there is nothing to examine or iterate through. DOM processing produces a tree-structured model which gives you what you want.
查看本页中的初学者示例
YoLinux 解析 XML 教程
Check out the beginner's sample in this page
YoLinux Tutorial on Parsing XML
如果使用XercesDOMParser,在解析文档后仍然无法请求特定的键值对。 我最近遇到了同样的问题,在迭代 DOM 树时,我将所有键值对存储在 STL 映射中。 然后您可以稍后在程序中从映射请求键值对。
If you use the XercesDOMParser, there is still no way to request a specific key value pair after the document is parsed. I ran into the same problem recently, and while iterating through the DOM tree I stored all the key value pairs in an STL map. Then you can request key value pairs from the map later in the program.