[xml] code generation for C++

(warning: xml n00b)

Can anyone point me at a package that will generate c++ headers and code to
represent (and load using libxml2) a data structure defined by a DTD?  I
hacked one up in Perl but its parser is extremely brain-dead and so supports
only a very limited subset of possible DTDs (it can't handle much more than
the following example).

I want it to be able to take a DTD like this:

<!ELEMENT a (b,c*)>
        name CDATA #REQUIRED
        place CDATA #REQUIRED
        param (false|true) "false">

and generate classes for a, b & c, eg:

class xml_mydtd_a {
        xml_mydtd_a(xmlDocPtr, xmlNodePtr);
        virtual ~xml_mydtd_a();

        xml_mydtd_b *b;
        std::vector<xml_mydtd_c *> c;
        std::string name;
        std::string place;

class xml_mydtd_b {
        xml_mydtd_b(xmlDocPtr, xmlNodePtr);
        virtual ~xml_mydtd_b();

        enum param_ENUM {
        } param;

The generated code should be able to load each of those object types into
instances of the appropriate classes, allowing me to access them sensibly:

xmlDocPtr doc = xmlParseFile(docname);
xmlNodePtr cur = xmlDocGetRootElement(doc);
xml_mydtd_a a = new xml_mydtd_a(doc, cur);

cout << a->name << " at " << a->place << " has b.param = " << a->b->param;
for(size_t i=0;i<a->c.size();++i)
        cout << " c[" << i << "] = " << a->c[i]->xmltext;
delete a;

you get the idea, bindings.  Does such a thing exist outside of my ratty
little script?  I had a look at gdome but it doesn't appear to do what I want.  
I get the impression that Quick and Zeus could be the right thing, but this is
not for a Java project.

Is it possible to feed a DTD to XSLT and use it to generate C++ instead of

William Brodie-Tyrrell

Moderation in all things, particularly moderation.

<wfbrodie smug adelaide edu au>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]