[XML-SIG] PyXML for py 2.5

Stefan Behnel stefan_ml at behnel.de
Mon Feb 25 06:46:00 CET 2008

Hi Martin,

Martin v. Löwis wrote:
>>> Mapping of Schema definitions to Python classes?
>> A combination of lxml.objectify and schema validation is close enough
>> to that,
>> IMHO, but not a bit less powerful, as it's C-implemented and completely
>> runtime configurable in Python code at basically any granularity.
> So can you also use that to generate documents from scratch? Suppose I have
> <element name="Person">
>  <complexType>
>    <sequence>
>      <element name="first" type="string"/>
>      <element name="last" type="string"/>
>      <element name="age" type="integer"/>
> </element>
> then with lxml.objectify, how would I spell
>   p = Person(first="Monika", last="Mustermann", age=57)
>   p.toxml()

As the docs tell you to:

    from lxml.objectify import E, deannotate
    from lxml.etree import tostring

    # this is the line you want:
    p = E.person(E.first("Monika"), E.last("Mustermann"), E.age(57))

    # now do whatever you like with p here, for example:
    p.age += 1
    p.last = "Musterfrau"

    deannotate(p) # remove type hints
    tostring(p)   # serialise

>>> XML 1.1?
>> Honestly - what for?
> To parse it, should you ever see documents that use it. In the language
> for best XML processing, it's reasonably to expect that this
> implemented, no? Xerces 2.9 for Java supports it.

Fine. I've never seen an XML 1.1 document in the wild. Real-life applications
tend to avoid them as people know they're not portable (and XML is about
platform independence and portability and all that...)

>>> XML Encryption and Signature?
>> Should be easy to wrap libxmlsec if you need it.
>> http://www.aleksey.com/xmlsec/
> Perhaps. In Java, I get working implementations without further work.

Ok, fine. We never had a request on the lxml list so far. Maybe people just
don't use it (yet). But if someone needs it, it's not hard to enable. The
implementation is there, it's just the binding to lxml that is missing. So
just add that to the number of implementation weeks for your entire
application and then go and compare that to a pure Java implementation.

>> If you start with ElementTree and find that you need a feature that isn't
>> supported there, chances are high that you will either find it in lxml
>> or that
>> it would be easy to add to it if you really feel like needing it.
> So how about a web services stack :-?

Web services are not so much about XML processing (anymore) as you might
think. They are more about hiding XML (and networking and...) than about
processing it. So I don't really see the link to ElementTree or lxml here.

That said, Google says it has some 5 million hits for "web service python":


including this:


but I have no idea how useful/usable/well-designed the tools are here.


More information about the XML-SIG mailing list