dynamic class instantiation



Hi, I have a "language definition" file, something along the lines of:

page ::
name : simple
caption : simple
function : complex

function ::
name : simple
code : simple

component ::
name : simple
type : simple
dataset : complex

etc.

On the other hand as input I have .xml files of the type:

<page>
<name>WebPage</name>
<caption>Browser Visible Caption</caption>
<component>
<name>Countrylist</name>
<type>dropdown</type>
<value>$dropdownlist</value>
<function>
<name>sqlSelect</name>
<code>select countries
from blah into $dropdownlist</code>
</function>
</component>
</page>

I have a parser that will go through the language definition
file and produce the following as a separate .py file:

class page(object):
def __init__():
self.name = None
self.caption = None
self.functions = []

class function(object):
def __init__():
self.name = None
self.code = None

Now I want to use something like xml.dom.minidom to "parse" the
..xml file into a set of classes defined according to the "language
definition" file. The parse() method from the xml.dom.minidom
package will return a document instance and I can get the node
name from it. Say I got "page" as a string. How do I go about
instantiating a class from this piece of information? To make it
more obvious how do I create the page() class based on the "page"
string I have? I want to make this generic so for me the language
definition file will contain pages, functions, datasets etc. but
for someone else mileage will vary.

Thanks,
Ognen
.



Relevant Pages

  • Re: dynamic class instantiation
    ... > On the other hand as input I have .xml files of the type: ... files instead of just defining everything as Python classes? ... language definition file (LDF), LDF to python parser is a LOT ...
    (comp.lang.python)
  • Re: C String Interop
    ... think you are confusing implementation with language specification. ... And then there is the question of what the length of a string would be. ... character past the end of the string length? ... consistently and simply in the language definition. ...
    (comp.lang.fortran)
  • Re: comparision between Python, Perl and TCL
    ... One interesting thing in Tcl is that the language definition (taken as ... Tcl script. ... Different commands interpret their words differently." ... and sometimes there are conflicting styles (just compare [string ...
    (comp.lang.tcl)