Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML to C struct and C struct to XML [closed]

I like to do my server side programming in C, but need to inter-operate with some XML.

What I need to write is some function that, given a C structure, or nested structure, and another structure (or nested structures) that describes the elements in the C structure, spits it out as XML. And another function that reads the XML, verifies that it matches the description of the C structures, and populates the C structures.

I'm quite certain this has been done many times before, but there is so much other info about XML out there that I'm not having any luck composing a Google query that doesn't return a lot of unrelated stuff.

I'm not looking for a library - just a few hundred lines of C code to parse the XML.

like image 307
Matthias Wandel Avatar asked May 08 '09 22:05

Matthias Wandel


2 Answers

He is not asking for an XML parser. He is asking for a library that automatically serializes/unserializes a complex C structure to and from XML (which obviously would rely on an XML parser underneath).

Libpdel is old but has support for doing what you want (via the "structs" stuff).

like image 70
Archie Avatar answered Oct 06 '22 05:10

Archie


One way you could do it if you don't find any premade libraries or code is to write a toXML() function like the usual toString() functions. Then a toStruct(char*) that deserializes the XML back into the struct

like image 25
ThePosey Avatar answered Oct 06 '22 06:10

ThePosey