Simple XML C Parser

This is what I need to do: I need to read an XML document and extract elements and their values โ€‹โ€‹from it, for example, in the following code:

<user name="Mark"> <param name="Age" value="21"/> <param name="Country" value="NL"/> </user> 

I need to extract: name = Mark, Age = 21 and Country = NL.

Until today, I did this analysis manually, which was painful.

Now I donโ€™t care if the file is โ€œvalid XMLโ€ or whatever, I donโ€™t care about DTD or other standard XML requirements. I just need to read and analyze the values.

Does anyone know (except lib eXpat) lib for this or code for this? Thanks!

Jess

EDIT:

Yes, I forgot to mention the platform: Windows and Linux. In plain C, not C ++

+7
c xml
source share
5 answers

Mini-XML looks promising

http://www.minixml.org/

0
source share
+7
source share

An expat parser is the best I have found - I use it in my C ++ code, preferring various C ++ parsers - but it is written in C. It is very easy to use and integrates into your application. Therefore, I do not understand why in your question you say:

(except lib eXpat)

Do you have anything against it?

+4
source share

What about Mini-XML? It is lightweight, works with gcc, is compatible with ANSI-C ...

http://www.minixml.org/index.php

According to the documentation, finding specific nodes will be as simple as:

 /* Find the first "a" element */ node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND); 

Once you get the node, you can manage it according to your requirements.

+4
source share

If C ++ is fine, you can try TinyXML . I have been using it for several years and it works well.

+1
source share

All Articles