XML API in C?

Are they all complicated ?: http://msdn.microsoft.com/en-us/library/ms766497(VS.85).aspx

You just need something basic to create XML in C.

+4
source share
5 answers

MiniXML may be what you are looking for if you need something simple, easy, and C:

Mini-XML: Lightweight XML Library

Mini-XML is a small XML library that you can use to read and write XML and XML data files in your application without requiring large non-standard libraries. Only mini-XML requires an ANSI C compatible compiler (GCC works like most ANSI C compilers) and a make program.

However, there is a ton of them in the range of complexity and needs. MiniXML is good in that it does not require more than a simple Ansi C compiler. Many of them require other libraries or specific compilers.

-Adam

+3
source

I like libxml . Here is a usage example:

#include <libxml/parser.h> int main(void) { xmlNodePtr root, node; xmlDocPtr doc; xmlChar *xmlbuff; int buffersize; /* Create the document. */ doc = xmlNewDoc(BAD_CAST "1.0"); root = xmlNewNode(NULL, BAD_CAST "root"); /* Create some nodes */ node = xmlNewChild(root, NULL, BAD_CAST "node", NULL); node = xmlNewChild(node, NULL, BAD_CAST "inside", NULL); node = xmlNewChild(root, NULL, BAD_CAST "othernode", NULL); /* Put content in a node: note there are special characters so encoding is necessary! */ xmlNodeSetContent(node, xmlEncodeSpecialChars(doc, BAD_CAST "text con&tent and <tag>")); xmlDocSetRootElement(doc, root); /* Dump the document to a buffer and print it for demonstration purposes. */ xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); printf((char *) xmlbuff); } 

Compiled using 'gcc -Wall -I / usr / include / libxml2 -c create-xml.c && & && & NKU -lxml2 -o create-xml create-xml.o', this program will display:

 % ./create-xml <?xml version="1.0"?> <root> <node> <inside/> </node> <othernode>text con&amp;tent and &lt;tag&gt;</othernode> </root> 

For a real example, see my implementation of RFC 5388 .

+7
source

Xerces is known to just give it a try

+4
source

The easiest way to make XML in C is with a high-quality and free genx from Tim Bray: http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus

+1
source

All Articles