XML-> C 解析器生成器
我有一个 ac 程序,它从 XML 文件获取其设置。目前我正在使用 Xerces 来遍历数据,但是将每个 XML 值映射到变量变得非常繁琐。
Java 程序也可以读取相同的 XML,这要方便得多,因为 JAXB 在 Java 中创建了所有必需的类等。我正在寻找类似的东西,可以创建“结构的结构”或类似的东西。重要的是我要获取 C 结构,而不是 C++ 类,因为此代码将在 GPU 上运行。
我找到了“XML Booster”,目前正在阅读它的文档。您知道其他选择吗?需要能够在linux下使用。
I have a c program, that gets its settings from an XML file. Currently I'm using Xerces to traverse the data, but it's getting quite tedious to map each XML-value to a variable.
The same XML is also read by a Java program, which is much more convenient due to JAXB creating all the necessary classes and such in Java. I'm looking for something similar that can create a "structure of structs" or some such. It's important that I get c structs, and not c++ classes, because this code will run on GPUs.
I found "XML Booster", and am currently reading it docs. Do you know of other options? Needs to be usable in linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 libxml 库。您仍然需要遍历 XML,但您会得到一个包含元素、属性、节点和子节点的链表,您可以跟踪它们。
链接:http://xmlsoft.org/index.html
i use the libxml library. You still have to traverse the XML, but you get a linked list with elements, attribues, nodes and children-nodes, which you can follow.
link: http://xmlsoft.org/index.html
鉴于您的 XML 文件具有通用模式,您可以使用 Bison+Flex 或简单的 ANTLR(C 运行时)来构建语法并将 XML 文件中的值提取到变量。这些将生成纯 C 语言的解析器,因此您无需担心。
Given your XML files have common pattern, you can use Bison+Flex or simply ANTLR (C runtime) to construct grammar and extract the values from the XML files to variables. Those will produce parsers in pure C so you have nothing to worry about.
如果您有 xml 架构,请查看 xsd codesynthesis。它为您的 xsd 生成漂亮的 C++ 对象,并且您不需要直接处理 xerces:
http://www.codesynthesis.com/products/xsd/
If you have an xml schema, check out xsd codesynthesis. It generates nice c++ objects for your xsd and you don't need to deal with xerces directly:
http://www.codesynthesis.com/products/xsd/