简体   繁体   English

在纯 C 中解析 XML

[英]Parsing XML in Pure C

在纯 C 中解析 XML 数据的首选库是什么?

C 的规范 XML 解析库是libxml2

两个流行的选择是expatlibxml2

Here is a list of libraries for multiple languages, including C:以下是多种语言的库列表,包括 C:

http://www.xml.com/pub/rg/XML_Parsers http://www.xml.com/pub/rg/XML_Parsers

Not 'the preferred library', but there's also http://www.minixml.org/ .不是“首选库”,但也有http://www.minixml.org/

Mini-XML is a small XML library that you can use to read and write XML and XML-like data files in your application without requiring large non-standard libraries. Mini-XML 是一个小型 XML 库,您可以使用它在应用程序中读取和写入 XML 和类似 XML 的数据文件,而无需大型非标准库。 Mini-XML only requires an ANSI C compatible compiler (GCC works, as do most vendors' ANSI C compilers) and a 'make' program. Mini-XML 只需要一个 ANSI C 兼容的编译器(GCC 可以工作,就像大多数供应商的 ANSI C 编译器一样)和一个“make”程序。

Mini-XML supports reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and strings. Mini-XML 支持读取 UTF-8 和 UTF-16 以及写入 UTF-8 编码的 XML 文件和字符串。 Data is stored in a linked-list tree structure, preserving the XML data hierarchy, and arbitrary element names, attributes, and attribute values are supported with no preset limits, just available memory.数据存储在链表树结构中,保留 XML 数据层次结构,并且支持任意元素名称、属性和属性值,没有预设限制,只有可用内存。

VTD-XML 是您应该研究的一种,如果您想要结合易用性、性能和效率

You can consider miniML-Parser , a simple and tiny XML parser library in C. It is specifically developed for embedded applications in mind.您可以考虑miniML-Parser ,它是 C 语言中的一个简单而微型的 XML 解析器库。它专为嵌入式应用程序而开发。

  • It is extremely easy to use: You need to call only one API to parse your XML data它非常易于使用:您只需调用一个 API 即可解析您的 XML 数据
  • It has a very small footprint: The parser uses only 1.8 kB1 of code memory.它占用空间非常小:解析器仅使用 1.8 kB1 的代码内存。 Hence, you can use it in very small embedded applications.因此,您可以在非常小的嵌入式应用程序中使用它。
  • It is a validating XML parser.它是一个验证 XML 解析器。
  • It also extracts the content of XML data and converts it to its specified data type.它还提取 XML 数据的内容并将其转换为指定的数据类型。
  • It comes with a tool to generate the source code from XML schema file, instead of manually writing XML tree structure in C.它带有一个从 XML 模式文件生成源代码的工具,而不是在 C 中手动编写 XML 树结构。

Disclosure: I'm author of this miniML-Parser披露:我是这个 miniML-Parser 的作者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM