Python code from XMLSchema?

Discussion in 'Python' started by Russell Lear, Jul 2, 2004.

  1. Russell Lear

    Russell Lear Guest

    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.
    Russell Lear, Jul 2, 2004
    #1
    1. Advertising

  2. Russell Lear

    Dave Kuhlman Guest

    Russell Lear wrote:

    > 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]


    --
    Dave Kuhlman
    http://www.rexx.com/~dkuhlman
    Dave Kuhlman, Jul 2, 2004
    #2
    1. Advertising

  3. Brian Quinlan, Jul 2, 2004
    #3
  4. Russell Lear

    Dave Kuhlman Guest

    Brian Quinlan wrote:

    > Dave Kuhlman wrote:
    >> http://www.rexx.com/~dkuhlman/gnosis_generateds.html

    >
    > 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

    --
    Dave Kuhlman
    http://www.rexx.com/~dkuhlman
    Dave Kuhlman, Jul 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sudha
    Replies:
    0
    Views:
    358
    sudha
    Jun 30, 2003
  2. Marcin Wielgus

    XMLSchema, validation

    Marcin Wielgus, Mar 16, 2006, in forum: Java
    Replies:
    0
    Views:
    658
    Marcin Wielgus
    Mar 16, 2006
  3. Mattias
    Replies:
    1
    Views:
    426
    Martin Honnen
    Dec 4, 2003
  4. BODIN
    Replies:
    0
    Views:
    615
    BODIN
    Dec 8, 2003
  5. Robert Ludewig

    XMLSchema and XML Validation problem

    Robert Ludewig, Jun 28, 2004, in forum: XML
    Replies:
    4
    Views:
    588
    Martin Honnen
    Jun 28, 2004
Loading...

Share This Page