Python code from XMLSchema?

R

Russell Lear

I need to be able to unmarshall data from an XML file into (instances of)
appropriate Python classes . I don't have control over the schema used.

I'd like the Python classes to use lists for elements whose XMLSchema spec
has maxOccurs > 1, simple attributes for maxOccurs = minOccurs = 1, dict
for element attributes, etc.

In the past I've just used SAX and hand-written the parsing - a
straightforward, fairly mechanical task. In short, perfect for a tool.

I've poked a little through the PyXML collection but don't really see what I
want (although I could be missing it). Does someone know of a tool to do
this kind of thing? Perhaps taking an XMLSchema with a cleverly written
XSLT script to do the transform?

Or am I making this harder than it has to be?

Thanks for any pointers,
Russell.
 
D

Dave Kuhlman

Russell said:
I need to be able to unmarshall data from an XML file into
(instances of)
appropriate Python classes . I don't have control over the schema
used.

I'd like the Python classes to use lists for elements whose
XMLSchema spec has maxOccurs > 1, simple attributes for maxOccurs
= minOccurs = 1, dict for element attributes, etc.

Here are links to two different solutions: generateDS.py and
xml_objectify. One is shameless self-promotion; you will have to
figure out which.

http://www.rexx.com/~dkuhlman/generateDS.html
http://gnosis.cx/publish/programming/xml_matters_2.txt

And, here is a document that compares the above two approaches:

http://www.rexx.com/~dkuhlman/gnosis_generateds.html

And, if you are considering the use of XSLT, you may also be
interested in the following document, which describes the use of
generateDS.py as an alternative to XSLT:

http://www.rexx.com/~dkuhlman/xsltvsgenerateds.html

Dave

[snip]
 
D

Dave Kuhlman

Brian said:
Why do you think that XSLT is not a "full programming language"?

Because I'm biased and prejudiced and pig-headed?

XSLT seems very special purpose to me.

Many years ago, I took a class in "comparative programming
languages" from a professor who loved to say: "I can do A in X.",
where A was some task that was very inappropriate for language X,
for example string processing in FORTRAN, numerical analysis in
Lisp, etc. So, why don't we write a mail reader in XSLT or maybe
we could re-write the Python C code implementation in XSLT.

OK. I'm being silly, but you get my point.

What is the technical term for a "full" or "complete" programming
language? Turing complete? Is XSLT Turing complete? I suppose it
is. But it still seems special purpose to me.

For me, saying that Python is a full programming language and XSLT
is not is similar to saying that Python is good and Perl is bad.
That claim is not defensible but is totally true.

But then you already knew that I'm biased and prejudiced and
pig-headed.

Dave
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top