Commandline
What is it?
Download
History
Progarmming
Compile
Documentation
Mel is a new system which allows you to store your data in XML without having to worry about parsing the XML or killing a family of ferrets to sacrifice them to the XML gods. Simply write your DTD (or XSD) to describe the data relationships, then run mel and give mel: the directory where you placed mel.c.template, mel.h.template and mellib.h; the root node's name; and the name of the DTD file. Mel will produce a .h file which will have all your C structures all laid out for you, and a .c file that provides the functions mentioned in the .h file and will call functions in mellib.a which must be linked against your final application.
For your info, we tried [ .. X1 ..], it generates 115k lines of code. Just plain horrible for an embedded system, and so difficult to modify... And it's a commercial software.... Tried [ .. X2 .. ], it just makes a mockery of the whole thing, just wrapping the usual DOM with get and set functions specific to schema... . And mel is a little and cute piece of work, ya it doesn't do some things in schema... but the design as such is the best I saw in C/C++ code generation tools I tried...
The things it doesn't do yet in schema will come when someone gets around to it.
For more information see Documentation page.
This is the eighth alpha release of mel, the XML-DATA-BINDING program for C.
To verify it will partialy work on your system:
make tests cd schema make tests
You may want to remove the $(CFLAGS2) from the Makefile if you don't get a compile. I like it because I am pedantic and want the compiler to catch as many errors as possible, but it may not work on your system.
The first command above will make a program called mel and a library libmel.a and then create a sample program in testdir/ and run tests on it to make sure it reads in the sample files correctly.
Then the lines above instruct you to
cd into the schema directory and make tests
again. This will
produce the schema reading program xsd2c
. Read the Makefile in that
directory to see how it is used.
To Use the mel
./mel [-d] [-hfile] [-Idir] [-cfile] [-r rootelement] [--] filename.dtd where: -d debug (outputs some mildly useful debug messages -h file make header file be called 'file' -n do not produce the header file (in case it has been edited) -p pref prefix to all c structure names and structure fields to avoid conflicting names with reserved words -I dir look for mellib.h, melstack.h and templates in this dir -c file make .c file be called 'file' -r root make 'root' be the name of the toplevel element will also set .c file to root.c and .h file root.h if -h and -c are not specified -- no more argument processing filename.dtd read this DTD file (sorry, mel does not yet handle .xsd or other schemas)
mel will create two files in the current directory:
foo.c and foo.h
To use them you can call the functions defined in the foo.h file. And to build you must link against libxml (preferably libxml2) from the gnome system.
As usual, bug report, fixes and enhancements will be appreciated.
WHAT IT IS (or should be):
Smaller and faster and simpler than DOM.
WHAT IT IS NOT:
DOM: if you want a generalized XML memory system, look for a DOM implementation
handling MIXED and ANY: This was sacrificed to make an easier interface.
Or rework your DTD to put <> </> around each bit of PCDATA.
But note that order of non same type elements will not be kept.
HTML hanlder: forget it & look at DOM.
If this might be what you're looking for: The SourceForge project page has more information. Or simply download the 2004 January 2nd Release.
While reading over the .h file produced by mel, you may notice the use of the
macro Stack()
and sudden appearances of struct types ending in
_stack
.
Stack()
is a macro that expands into a resizable array of pointers
to objects that have the type of the first argument to stack and in the
process creates a struct with the name of the second argument plus _stack. So
Stack(xmlChar, stations);
expands to something like
struct stations_stack {
xmlChar **contents;
int num;
} stations;
although, you should never access the fields of this structure directly.
To use a _stack
, #include "melstack.h"
and use any
of the following macros.
Stack_init(_stackptr);
:set up or destroy stackStack_destroy(_stackptr);
:free arrayStack_push(_stackptr, obj);
:Push obj onto stackStack_pop(_stackptr);
:Pop obj from stackStack_size(_stackptr);
:returns size of stackStack_get(_stackptr, j);
:return j'th item from bottom
A user should never have to worry about casting or accidentally assigning a
returned pointer to the wrong type. The type information is maintained and
found at compile time.
Note: in the case where you have
struct st {
Stack(struct homes, homes);
} street;
to call any of these functions, you have to include an & as in
Stack_push(&street.homes, home1);
To compile your program, you must add -Idir
where dir is the
directory that has melstack.h
and mellib.h
when
compiling the .c files. You must also add -Ldir -lmellib.a -lxml2
where dir is again the directory that has mellib.a in it.
See the Makefile in testdir for an example.