OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   [ANN] new XML reader and writer

[ Lists Home | Date Index | Thread Index ]

I'm releasing two projects of mine, Ali and Alo.  They're at SourceForge.net

http://alo.sourceforge.net/
http://ali.sourceforge.net/

Alo is a concise way in ANSI C code to write data in XML format to a 
file.  I got tired of using fprintf.


Ali is an XML parser that reads structured XML data into C data 
structures in a way convenient for your ANSI C code. The result is that 
your code is smaller and easy to understand. Most other solutions like 
SAX and require many callback functions.

Suppose 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:

/* The first function opens the xml document, reads it, and closes it. */
{
    rootN = ali_open(&doc, "person.xml", true, &data);

    if (doc.error == ALI_ERROR_NONE)
    {
       personN = ali_in(doc, rootN, "^e%f", 0, "person", parse_person);
       ali_close(&doc);
    }
}

/* The second function parses the person element. */
static void
parse_person(ali_doc_info *doc, ali_element_ref personN, void * data, 
bool new_element)
{
    my_person_struct * person = a_new_person(data);

    if (!doc->error) ali_in(doc, personN, "^a%d", 0, "id", &person->id);
    if (!doc->error) ali_in(doc, personN, "^e%s", 0, "name", &person->name);
    if (!doc->error) ali_in(doc, personN, "^e%u", 0, "zipcode", 
&person->zipcode);
    if (!doc->error) ali_in(doc, personN, "^e%s", 0, "state", 
&person->state);
}



Writing XML using Alo is basically the opposite, and about the same 
amount of work.

Both projects are small. Alo is about 4KB and Ali 7KB compiled.

I wrote them so an app of mine could load and save it's dat in XML/RDF 
and realized I should make them available to others.  Ali isn't a 
conforming XML processor 
(http://www.w3.org/TR/2004/REC-xml-20040204/#dt-xml-proc) because it's 
fairly incomplete compared to the XML spec.  Alo supports more XML 
notations than Ali because it's easier to code a writer than a reader. 
But they both cover my XML data needs.

Take a look and try them and let me know what you think.  They're both 
early in development.  There are no known bugs, but there are missing 
features!

-Roger Flores
mailto:roger.flores@pacbell.net





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS