1

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but is there a large difference between libxml and xerces? I already get a list of nodes and that I for-loop over. I might just missunderstand something basic about how libxml works, but I took a look at it an concluded it wouldn't improve the situation.
i do not know Xerces. I was "Answering" your "map each XML-value to a variable" part.
I appreciate that you answered my question, but "map each XML-value to a variable" is the problem I'm trying to get away from, not re-create :)
LibXML is great, but it's comparable to a Xerces written in C. It's simple to embed, and solid as a tank, but wouldn't significantly change your method.
1

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.

Comments

0

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/

2 Comments

That's a great option, but I should have expressed myself more clearly in the question. Classes are not an option, as the bulk of the application runs on GPUs. I need pure C code. I've updated my question to reflect this better.
That's why you need to consider Bison+Flex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.