重量轻 C++ SAX XML 解析器
我知道至少三个轻量级 C++ XML 解析器:RapidXML、TinyXML 和 PugiXML >。然而,这三个都使用基于 DOM 的接口(即,它们构建自己的 XML 文档内存中表示,然后提供一个接口来遍历和操作它)。对于我必须处理的大多数情况,我更喜欢 SAX 接口(其中解析器只是吐出诸如标记开始之类的事件流,应用程序代码负责根据这些事件执行它想要的操作) 。
谁能推荐一个带有 SAX 接口的轻量级 C++ XML 库?
编辑:我还应该注意到 Microsoft XmlLite 库,它确实使用 SAX 接口(嗯,实际上是一个“拉”接口,可能更好)。不幸的是,目前我已经排除了这种可能性,因为据我所知它是闭源的并且仅限 Windows(如果我在这一点上错了,请纠正我)。
I know of at least three light weight C++ XML parsers: RapidXML, TinyXML and PugiXML. However, all three use a DOM based interface (ie, they build their own in-memory representation of the XML document and then provide an interface to traverse and manipulate it). For most situations that I have to deal with, I much prefer the SAX interface (where the parser just spits out a stream of events like start-of-tag, and the application code is responsible for doing whatever it wants based on those events).
Can anyone recommend a light weight C++ XML library with a SAX interface?
Edit: I should also note the Microsoft XmlLite library, which does use a SAX interface (well, actually a "pull" interface which is possibly even better). Unfortunately, it's ruled out for me at the moment since as far as I know it's closed source and Windows only (please correct me if I'm wrong on this).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我需要解析 XML 时,我使用了 expat 。它非常轻量(嗯,以前是这样;我已经有一段时间没有做过 XML 的工作了)并且可以胜任这项工作。
I've used expat when I needed to parse XML. It's very light-weight (well, it used to be; it's a while since I've done XML stuff) and does the job.
你可以尝试 https://github.com/thinlizzy/die-xml 。它似乎非常小并且易于使用
,这是一个最近开源的 C++0x XML SAX 解析器,作者愿意反馈
它解析输入流并在与
堆栈机使用的 std::function 兼容的回调上生成事件有限自动机作为后端,一些事件(开始标签和文本节点)使用迭代器来最小化缓冲,使其非常轻量级
you can try https://github.com/thinlizzy/die-xml . it seems to be very small and easy to use
this is a recently made C++0x XML SAX parser open source and the author is willing feedbacks
it parses an input stream and generates events on callbacks compatible to std::function
the stack machine uses finite automata as a backend and some events (start tag and text nodes) use iterators in order to minimize buffering, making it pretty lightweight
PugiXML 和 RapidXML 没有符合 DOM 的接口。这些 API 在功能和一致性方面存在严重限制。您可能想要研究比 DOM 或 SAX/Pull 先进得多的 VTD-XML
PugiXML and RapidXML do not have DOM conforming interfaces.. those API came with severe limitations on functionalities and conformance. You might want to investigate VTD-XML that is signifiantly more advanced than either DOM or SAX/Pull