Skip to content

comm-lab/cxml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cxml

Introduction

This is a simple XML pull parser written in C. Its features:

  • Two file (*.h *.c) implementation
  • No dynamic allocation
  • No external dependency (not even libc)
  • C99 standard

To use the library, just add the files cxml.c and cxml.h to your project. If you need some type conversion functions (these rely on libc), include also cxml_types.c and cxml_types.h.

Note

Warning! this library has been written to be used in embedded environment so while it is very simple and lightweight, it may contain bugs.

Usage example

const char* XML = 
    "<Root>"
    "   <Item num='1'/>"
    "   <Item num='2'/>"
    "   <Child>Lorem ipsum</Child>"
    "</Root>";

struct XmlDocument doc;
xml_document_create(&doc, XML, strlen(XML));

int event;
while ((event = xml_read(&doc)) != XML_EOF) {
    switch (event)
    {
    case XML_TAG_BEGIN: {
        struct XmlString name = xml_name(&doc);
        ...
        break;
    }

    case XML_ATTRIBUTE: {
        struct XmlString name = xml_attr_name(&doc);
        struct XmlString value = xml_attr_value(&doc);
        ...
        break;
    }
    
    case XML_TEXT: {
        struct XmlString text = xml_text(&doc);
        ...
        break;
    }

    default: break;
    }
}

About

Simple C XML pull parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •