Generating class definitions at runtime in memory from XSD or JSON

S

Stodge

Does anyone know of a library to generate class definitions in memory,
at runtime, from XSD or JSON? I know about PyXB, generateDS and some
others, but they all rely on generating python source files at the
command line, and then using those to parse XML.

Thanks
 
N

Nobody

Does anyone know of a library to generate class definitions in memory,
at runtime, from XSD or JSON? I know about PyXB, generateDS and some
others, but they all rely on generating python source files at the
command line, and then using those to parse XML.

You don't need a library to generate classes. If the type() function is
called with 3 arguments, it creates and returns a new class. The first
argument is the name of the class, the second argument a tuple of base
classes, the third argument is the class' dictionary. E.g.:

class Foo(Bar, Baz):
def __init__(self):
pass

could be written as:

def foo_init(self):
pass

Foo = type('Foo', (Bar, Baz), {'__init__': foo_init})

If you want to generate the function bodies from the contents of the
JSON or XML file, use exec().
 
S

Stefan Behnel

Stodge, 17.02.2012 02:15:
Does anyone know of a library to generate class definitions in memory,
at runtime, from XSD or JSON?

The question is: why do you want to do that? There may be other ways to do
what you *actually* want to do, but we don't know what that is.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top