Why is there no functional xml?

Rustom Mody rustompmody at gmail.com
Mon Jan 22 22:53:21 EST 2018


On Sunday, January 21, 2018 at 4:51:34 PM UTC+5:30, Peter Otten wrote:
> Personally I'd probably avoid the extra layer and write a function that 
> directly maps dataclasses or database records to xml using the conventional 
> elementtree API.

Would appreciate your thoughts/comments Peter!

I find that you can get 'E' from lxml.objectify as well as lxml.builder
builder seems better in that its at least sparsely documented
objectify seems to have almost nothing beyond the original David Mertz' docs

builder.E seems to do what objectify.E does modulo namespaces

builder.E and objectify.E produce types that are different and look backwards
(at least to me — Elementbase is less base than _Element)

You seem to have some reservation against objectify, preferring the default 
Element — I'd like to know what

Insofar as builder seems to produce the same type as Element unlike objectify
which seems to be producing a grandchild type, do you have the same reservations
against builder.E?
--------------
$ python3
Python 3.5.3 (default, Nov 23 2017, 11:34:05) 
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from lxml.etree import Element, tostring
>>> from lxml.builder import E as Eb
>>> from lxml.objectify import E as Eo

>>> e = Element("tag")
>>> tostring(e)
b'<tag/>'
>>> o = Eb.tag()
>>> o
<Element tag at 0x7f058406ec08>
>>> tostring(o)
b'<tag/>'
>>> o = Eo.tag()
>>> tostring(o)
b'<tag xmlns:py="http://codespeak.net/lxml/objectify/pytype" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
>>> b = Eb.tag()
>>> tostring(b)
b'<tag/>'
>>> type(b)
<class 'lxml.etree._Element'>
>>> type(b).__bases__
(<class 'object'>,)
>>> type(e)
<class 'lxml.etree._Element'>
>>> type(o)
<class 'lxml.objectify.ObjectifiedElement'>
>>> type(o).__bases__
(<class 'lxml.etree.ElementBase'>,)
>>> type(o).__bases__[0].__bases__
(<class 'lxml.etree._Element'>,)
>>> 

--------------



More information about the Python-list mailing list