[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*)>
<!ATTLIST a
        name CDATA #REQUIRED
        place CDATA #REQUIRED
        >
<!ELEMENT b EMPTY>
<!ATTLIST b
        param (false|true) "false">
<!ELEMENT c (#PCDATA)>

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

class xml_mydtd_a {
public:
        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 {
public:
        xml_mydtd_b(xmlDocPtr, xmlNodePtr);
        virtual ~xml_mydtd_b();

        enum param_ENUM {
                param_false,
                param_true
        } 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
HTML?


William Brodie-Tyrrell

--
Moderation in all things, particularly moderation.

<wfbrodie smug adelaide edu au>
http://www.cs.adelaide.edu.au/~william








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