什么是 C++ 的最佳开放 XML 解析器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/170686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:25:37  来源:igfitidea点击:

What is the best open XML parser for C++?

c++xmlopen-source

提问by whaledawg

I am looking for a simple, clean, correct XML parser to use in my C++ project. Should I write my own?

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

回答by jk.

How about RapidXML? RapidXML is a very fast and small XML DOM parser written in C++. It is aimed primarily at embedded environments, computer games, or any other applications where available memory or CPU processing power comes at a premium. RapidXML is licensed under Boost Software License and its source code is freely available.

RapidXML怎么?RapidXML 是一个用 C++ 编写的非常快速和小型的 XML DOM 解析器。它主要针对嵌入式环境、计算机游戏或任何其他需要可用内存或 CPU 处理能力的应用程序。RapidXML 在 Boost 软件许可下获得许可,其源代码可免费获得。

Features

特征

  • 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.
  • 解析速度(包括 DOM 树构建)接近对相同数据执行 strlen 函数的速度。
  • 在现代 CPU(截至 2008 年)上,解析器吞吐量约为每秒 10 亿个字符。请参阅在线手册中的性能部分。
  • 代码和创建 DOM 树的内存占用小。
  • 仅标头的实现,简化了集成过程。
  • 简单的许可证,允许用于几乎任何目的,商业和非商业,没有任何义务。
  • 支持 UTF-8 和部分 UTF-16、UTF-32 编码。
  • 除了 C++ 标准库的一个非常小的子集之外,没有依赖项的可移植源代码。
  • 这个子集非常小,如果不希望使用标准库,它可以很容易地手动模拟。

Limitations

限制

  • The parser ignores DOCTYPE declarations.
  • There is no support for XML namespaces.
  • The parser does not check for character validity.
  • The interface of the parser does not conform to DOM specification.
  • The parser does not check for attribute uniqueness.
  • 解析器忽略 DOCTYPE 声明。
  • 不支持 XML 命名空间。
  • 解析器不检查字符有效性。
  • 解析器的接口不符合 DOM 规范。
  • 解析器不检查属性唯一性。

Source: wikipedia.org://Rapidxml

来源:wikipedia.org: //Rapidxml



Depending on you use, you may use an XML Data Binding? CodeSynthesis XSDis an XML Data Binding compiler for C++ developed by Code Synthesis and dual-licensed under the GNU GPL and a proprietary license. Given an XML instance specification (XML Schema), it generates C++ classes that represent the given vocabulary as well as parsing and serialization code.

根据您的用途,您可能会使用 XML 数据绑定?CodeSynthesis XSD是由 Code Synthesis 开发的用于 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.

CodeSynthesis XSD 的独特功能之一是它支持两种不同的 XML Schema 到 C++ 的映射:内存中的 C++/Tree 和面向流的 C++/Parser。C++/Tree 映射是具有树状内存数据结构的传统映射。C++/Parser 是一种新的、类似于 SAX 的映射,它将存储在 XML 实例文档中的信息表示为特定于词汇表的解析事件的层次结构。与 C++/Tree 相比,C++/Parser 映射允许处理不适合内存的大型 XML 文档、执行面向流的处理或使用现有的内存中表示。

Source: wikipedia.org://CodeSynthesis XSD

来源:wikipedia.org: //CodeSynthesis XSD

回答by Zbyl

pugixml- Light-weight, simple and fast XML parser for C++ Very small (comparable to RapidXML), very fast (comparable to RapidXML), very easy to use (betterthan RapidXML).

pugixml- 用于 C++ 的轻量级、简单且快速的 XML 解析器 非常小(与 RapidXML 相当),非常快(与 RapidXML 相当),非常易于使用(比 RapidXML更好)。

回答by Kasprzol

TiCPPis a "more c++" version of 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+

“TiCPP”是正式名称 TinyXML++ 的缩写。它是 TinyXML ( http://www.grinninglizard.com/tinyxml/) 的全新接口,使用了 C++ 的许多优势。模板、异常和更好的错误处理。它也在 doxygen 中有完整的记录。这真的很酷,因为这个版本让你以与以前完全相同的方式接口,或者你可以选择使用新的 'ticpp' 类。您需要做的就是定义 TIXML_USE_TICPP。它已在 VC 6.0、VC 7.0、VC 7.1、VC 8.0、MinGW gcc 3.4.5 和 Linux GNU gcc 3+ 中测试

回答by Kat

try this one: http://www.applied-mathematics.net/tools/xmlParser.html
it's easier and faster than RapidXML or PUGXML.
TinyXML is the worst of the "simple parser".

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

回答by yrp

Do not use TinyXML if you're concerned about efficiency/memory management (it tends to allocate lotsof tiny blocks). My personal favourite is RapidXML.

如果您担心效率/内存管理(它往往会分配大量小块),请不要使用 TinyXML 。我个人最喜欢的是RapidXML

回答by yrp

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.

gSOAP怎么?它是开源的,在 GPL 许可下免费提供。尽管名为 gSOAP 工具包,但它是一个通用的 XML 数据绑定工具,允许您将 C 和 C++ 数据自动绑定到 XML。无需使用 XML 解析器 API,只需让它为您读取/写入 XML 格式的数据即可。如果您真的需要一个超级简单的 C++ XML 解析器,那么 gSOAP 可能是一种矫枉过正。但就其他所有方面而言,自 2001 年引入 gSOAP 以来,它在许多工业应用程序中都表现得很好。

Here is a brief list of features:

以下是功能的简要列表:

  • 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 withI/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.
  • 便携:Windows、Linux、Mac OS X、Unix、VxWorks、Symbian、Palm OS、WinCE等。
  • 占用空间小:73KB 代码和不到 2K 数据来实现 XML Web 服务客户端应用程序(没有 DOM 来限制内存使用)。
  • 快速:不要相信其他工具的说法,真正的速度应该I/O来衡量。对于 gSOAP,它是通过 TCP/IP 的 3000 多个往返 XML 消息。XML 解析开销可以忽略不计,因为它是在(反)序列化发生时对输入/输出的简单线性扫描。
  • XML 支持:XML 模式 (XSD) 导入/导出、WSDL 导入/导出、XML 命名空间、XML 规范化、带附件的 XML (MIME)、DOM 的可选使用、生成带有缩进的 XML 的许多选项、使用 UTF8 字符串等。
  • XML 验证:部分和完整(选项)
  • WS 支持:WS-Security、WS-ReliableMessaging、WS-Addressing、WS-Policy、WS-SecurityPolicy 等。
  • 调试:带有泄漏检测、日志记录的集成内存管理。
  • API:无需学习API,只需要“soap”引擎上下文初始化,然后使用你的数据读写接口,“soap”引擎上下文销毁。

For example:

例如:

class Address
{ 
  std::string name;
  std::vector<LONG64> number;
  time_t date;
};

Then run "soapcpp2" on the Addressclass declaration above to generate the soap_read_Addressand soap_write_AddressXML reader and writer, for example:

然后在Address上面的类声明上运行“soapcpp2”来生成soap_read_Addresssoap_write_AddressXML 读写器,例如:

Address *a = new Address();
a = ...;
soap ctx = soap_new();
soap_write_Address(ctx, a);
soap_end(ctx);
soap_free(ctx);`

This produces an XML representation of the Address aobject. By annotating the header file declarations with XML namespace details (not shown here), the tools also generate schemas. This is a simple example. The gSOAP tools can handle a very broad range of C and C++ data types, including pointer-based linked structures and even (cyclic) graphs (rather than just trees).

这将生成Address a对象的 XML 表示。通过使用 XML 名称空间详细信息(此处未显示)注释头文件声明,这些工具还生成模式。这是一个简单的例子。gSOAP 工具可以处理非常广泛的 C 和 C++ 数据类型,包括基于指针的链接结构甚至(循环)图(而不仅仅是树)。

Hope this helps.

希望这可以帮助。

回答by Lev

TinyXML, and also Boost.PropertyTree. The latter does not fulfill all official requirements, but is very simple.

TinyXML 和 Boost.PropertyTree。后者不满足所有官方要求,但非常简单。

回答by Raminder

TinyXML can be best for simple XML work but if you need more features then try Xerces from the apache project. Go to the following page to read more about its features.

TinyXML 最适合简单的 XML 工作,但如果您需要更多功能,请尝试来自 apache 项目的 Xerces。转到下一页以阅读有关其功能的更多信息。

http://xerces.apache.org/xerces-c/

http://xerces.apache.org/xerces-c/

回答by godspeedelbow

I am a C++ newbieand after trying a couple different suggestions on this page I must say I like pugixmlthe most. It has easy to understand documentation and a high level API which was all I was looking for.

我是 C++新手,在此页面上尝试了几个不同的建议后,我必须说我最喜欢pugixml。它具有易于理解的文档和高级 API,这正是我一直在寻找的。