我正在寻找一个简单,干净,正确的XML解析器在我的c++项目中使用。我应该自己写吗?
当前回答
如果你关心效率/内存管理,不要使用TinyXML(它倾向于分配大量的小块)。我个人最喜欢的是RapidXML。
其他回答
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)。
TinyXML试试。
http://sourceforge.net/projects/tinyxml
尝试TinyXML或IrrXML…两者都是轻量级XML解析器(无论如何,我建议您使用TinyXML)。
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+
推荐文章
- 什么是“参数依赖查找”(又名ADL,或“Koenig查找”)?
- 公共朋友交换成员函数
- 如何在Go中使用c++
- 自定义c++分配器的引人注目的例子?
- RAII和c++中的智能指针
- 如何构建和使用谷歌TensorFlow c++ api
- 如何将XML转换成PHP数组?
- XMLHttpRequest Origin null不允许Access-Control-Allow-Origin for file:/// to file:///(无服务器)
- 断言是邪恶的吗?
- 下面这些短语在c++中是什么意思:0 -,default-和value-initialization?
- 在STL地图中,使用map::insert比[]更好吗?
- C++ Linux的想法?
- 如何为Fedora安装g++ ?
- Std::cin输入空格?
- c++标准是否要求iostreams的性能很差,或者我只是在处理一个糟糕的实现?