我正在寻找一个简单,干净,正确的XML解析器在我的c++项目中使用。我应该自己写吗?


当前回答

试试这个: http://www.applied-mathematics.net/tools/xmlParser.html 它比RapidXML或PUGXML更容易和更快。 TinyXML是最糟糕的“简单解析器”。

其他回答

我喜欢Gnome xml解析器。它是开源的(MIT许可,所以你可以在商业产品中使用它),速度快,并且有基于DOM和SAX的接口。

http://xmlsoft.org/

pugixml——轻量级、简单、快速的c++ XML解析器 非常小(可与RapidXML媲美),非常快(可与RapidXML媲美),非常容易使用(优于RapidXML)。

RapidXML怎么样?RapidXML是一个用c++编写的非常快速和小型的XML DOM解析器。它主要针对嵌入式环境、电脑游戏或任何其他需要大量内存或CPU处理能力的应用程序。RapidXML是根据Boost软件许可证授权的,其源代码是免费提供的。

特性

Parsing speed (including DOM tree building) approaching speed of strlen function executed on the same data. On a modern CPU (as of 2008) the parser throughput is about 1 billion characters per second. See Performance section in the Online Manual. Small memory footprint of the code and created DOM trees. A headers-only implementation, simplifying the integration process. Simple license that allows use for almost any purpose, both commercial and non-commercial, without any obligations. Supports UTF-8 and partially UTF-16, UTF-32 encodings. Portable source code with no dependencies other than a very small subset of C++ Standard Library. This subset is so small that it can be easily emulated manually if use of standard library is undesired.

限制

解析器忽略DOCTYPE 声明。 不支持XML名称空间。 解析器不会检查 字符的有效性。 解析器的接口没有 符合DOM规范。 解析器不会检查 属性的独特性。

来源:wikipedia.org Rapidxml: / /


根据您的使用,您可以使用XML数据绑定?CodeSynthesis XSD是一个由CodeSynthesis开发的c++ XML数据绑定编译器,在GNU GPL和私有许可证下双重授权。给定一个XML实例规范(XML Schema),它生成表示给定词汇表以及解析和序列化代码的c++类。

One of the unique features of CodeSynthesis XSD is its support for two different XML Schema to C++ mappings: in-memory C++/Tree and stream-oriented C++/Parser. The C++/Tree mapping is a traditional mapping with a tree-like, in-memory data structure. C++/Parser is a new, SAX-like mapping which represents the information stored in XML instance documents as a hierarchy of vocabulary-specific parsing events. In comparison to C++/Tree, the C++/Parser mapping allows one to handle large XML documents that would not fit in memory, perform stream-oriented processing, or use an existing in-memory representation.

来源: wikipedia.org://CodeSynthesis XSD

TinyXML试试。

http://sourceforge.net/projects/tinyxml

如果你关心效率/内存管理,不要使用TinyXML(它倾向于分配大量的小块)。我个人最喜欢的是RapidXML。