我正在寻找一个简单,干净,正确的XML解析器在我的c++项目中使用。我应该自己写吗?
TinyXML最适合简单的XML工作,但是如果你需要更多的特性,那么试试apache项目中的Xerces。转到下一页阅读更多关于它的功能。
http://xerces.apache.org/xerces-c/
我喜欢Gnome xml解析器。它是开源的(MIT许可,所以你可以在商业产品中使用它),速度快,并且有基于DOM和SAX的接口。
http://xmlsoft.org/
TiCPP是TinyXML的“更c++”版本。
'TiCPP' is short for the official name TinyXML++. It is a completely new interface to TinyXML (http://www.grinninglizard.com/tinyxml/) that uses MANY of the C++ strengths. Templates, exceptions, and much better error handling. It is also fully documented in doxygen. It is really cool because this version let's you interface tiny the exact same way as before or you can choose to use the new 'ticpp' classes. All you need to do is define TIXML_USE_TICPP. It has been tested in VC 6.0, VC 7.0, VC 7.1, VC 8.0, MinGW gcc 3.4.5, and in Linux GNU gcc 3+
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
How about gSOAP? It is open source and freely available under the GPL license. Despite its name, the gSOAP toolkit is a generic XML data binding tool and allows you to bind your C and C++ data to XML automatically. There is no need to use an XML parser API, just let it read/write your data in XML format for you. If you really need a super-simple C++ XML parser then gSOAP may be an overkill. But for everything else it has worked well as testimonials show for many industrial applications since gSOAP was introduced in 2001.
下面是一个简单的功能列表:
Portable: Windows, Linux, Mac OS X, Unix, VxWorks, Symbian, Palm OS, WinCE, etc. Small footprint: 73KB code and less than 2K data to implement an XML web service client app (no DOM to limit memory usage). Fast: do not believe what other tools claim, the true speed should be measured with I/O. For gSOAP it is over 3000 roundtrip XML messages over TCP/IP. XML parsing overhead is negligible as it is a simple linear scan of the input/output while (de)serialization takes place. XML support: XML schema (XSD) import/export, WSDL import/export, XML namespaces, XML canonicalization, XML with attachments (MIME), optional use of DOM, many options to produce XML with indentation, use UTF8 strings, etc. XML validation: partial and full (option) WS support: WS-Security, WS-ReliableMessaging, WS-Addressing, WS-Policy, WS-SecurityPolicy, and other. Debugging: integrated memory management with leak detection, logging. API: no API to learn, only "soap" engine context initialization, then use the read/write interface for your data, and "soap" engine context destruction.
例如:
class Address
{
std::string name;
std::vector<LONG64> number;
time_t date;
};
然后在上面的Address类声明上运行"soapcpp2"来生成soap_read_Address和soap_write_Address XML读取器和写入器,例如:
Address *a = new Address();
a = ...;
soap ctx = soap_new();
soap_write_Address(ctx, a);
soap_end(ctx);
soap_free(ctx);`
这将生成Address a对象的XML表示形式。通过用XML名称空间细节注释头文件声明(这里没有显示),这些工具还生成模式。这是一个简单的例子。gSOAP工具可以处理非常广泛的C和c++数据类型,包括基于指针的链接结构,甚至(循环)图(而不仅仅是树)。
希望这能有所帮助。
pugixml——轻量级、简单、快速的c++ XML解析器 非常小(可与RapidXML媲美),非常快(可与RapidXML媲美),非常容易使用(优于RapidXML)。
试试这个: http://www.applied-mathematics.net/tools/xmlParser.html 它比RapidXML或PUGXML更容易和更快。 TinyXML是最糟糕的“简单解析器”。
推荐文章
- 为什么我的程序不能在Windows 7下用法语编译?
- 如何获取变量的类型?
- 什么是奇怪的重复模板模式(CRTP)?
- 连接两个向量的最佳方法是什么?
- 在c++中,是通过值传递更好,还是通过引用到const传递更好?
- 在STL中deque到底是什么?
- Windows上最好的免费c++分析器是什么?
- 如何自动转换强类型枚举为int?
- 在一个类中使用具有成员函数的泛型std::function对象
- 'for'循环中的后增量和前增量产生相同的输出
- 虚函数和纯虚函数的区别
- c++中的_tmain()和main()有什么区别?
- 内存泄漏是否正常?
- 当启用c++ 11时,std::vector性能回归
- XML Schema minOccurs / maxOccurs默认值