Ali

What Is It?

Ali is a simple to use C API to parse XML data. It's scanf like approach is much easier than using SAX or DOM. A tutorial, complete reference documentation, and code examples in the download are all provided. Ali is pronounced like "Alley".

Latest Version

Ali 1.0 was released 1/20/2009.

Ali Example

Pretend you want to input address book data like:

<person id="1000">
    <name>Roger Flores</name>
    <zipcode>94062</zipcode>
    <state>CA</state>
</person>

You could write C code using Ali like this:

    /* Open the xml document, read it, and close it. */
    rootN = ali_open(&doc, "person.xml", ALI_OPTION_NONE, &my_data);
    if (doc != NULL)
    {
        personN = ali_in(doc, rootN, "^e", 0, "person");
        if (personN != 0)
        {
            person = a_new_person();
            ali_in(doc, personN, "^a%d", 0, "id", &person->id);
            ali_in(doc, personN, "^e%s", 0, "name", &person->name);
            ali_in(doc, personN, "^e%u", 0, "zipcode", &person->zipcode);
            ali_in(doc, personN, "^e%s", 0, "state", &person->state);
        }
        ali_close(doc);
    }

Notice the following points:
  1. The syntax is simple and concise. Reading data from an XML element into a variable can be done in one line.

  2. Familar scanf like reading is used to make handling formats easy. The "^e%s" reads an element and stores it in a string. A "^a%d" reads an attribute as a decimal number.

  3. The code follows the document, and is all together in one function. That keeps it easy to write.

A tutorial is available to quickly get started. By the end of the tutorial you will know enough to parse complicated XML, like RSS feeds using just your app's C code and Ali. The tutorial includes working code to read Slashdot's RSS feed! Also, a complete reference list of commands to read XML is in the documentation included with the distribution.

Ali is a about 15 KB compiled and can be easily added to your program. It is great for small or embedded projects.

Ali is LGPL licensed so you can simply link the library into your projects.

Alo

Alo is a matching project to write XML. Together they allow apps to save and load data files and preferences.

These have proven useful.

XML
XML is developed by the World Wide Web Consortium. It has the defining document for XML as well as several other technologies.
JEdit
JEdit is a nice editor for XML. It is a free Java editor that at least deserves a try.
WinMerge
WinMerge is an OK visual differ, and you need one when working on XML. It seems to be one of the better ones but could do more. My favorite visual diff tool is embedded in Metrowerk's CodeWarrior.
XML Schema
Resource Description Framework (RDF)
These W3C technologies allow better definitions of data, which are then used to reject invalid data. XML only gives syntax checking. If you believe in type checking, asserts, or checking error codes, then these are for you.
OWL Web Ontology Language
OWL is a way to describe how data relates to other data. If your XML document had a cat named FiFi and a dog named Brute you could add OWL information that "dogs chase cats". An OWL program could reason that Brute will chase FiFi, because your XML document allows for that, and not because the OWl knows anything about chasing, let aline cats or dogs. This gets cool when a program searches thousands of OWL documents to answer your questions.

Send comments to Roger Flores

SourceForge.net Logo