[lxml-dev] lxml.objectify.deannotate refuses to clean nil nodes
jholg at gmx.de
jholg at gmx.de
Tue Jun 2 09:59:02 CEST 2009
Hi,
> The nil node <Fubar/> is not deannotated as I would expect in the
> following
> snippet. I could not find a reference to this behaviour in the archives
> or
> documentation. Is this a design feature for which there is a work around,
> or a bug? I'm using lxml-2.2-py2.5-linux-i686.
Design feature. Only py:pytype/xsi:type attributes get removed by deannotate():
>>> print etree.__version__
2.1.5
>>> help(objectify.deannotate)
Help on built-in function deannotate in module lxml.objectify:
deannotate(...)
deannotate(element_or_tree, pytype=True, xsi=True)
Recursively de-annotate the elements of an XML tree by removing 'pytype'
and/or 'type' attributes.
If the 'pytype' keyword argument is True (the default), 'pytype' attributes
will be removed. If the 'xsi' keyword argument is True (the default),
'xsi:type' attributes will be removed.
IMHO the xsi:nil concept in XML Schema pretty much corresponds to NULL values in databases, i.e. a typed element/column may (or may not) be xsi:nil/NULL, but it does not so directly translate to the distinct Python None object. OTOH I think mapping xsi:nil to None very much captures the meaning of xsi:nil/NULL, because in most use cases you'd test if a value has been set (!=None) or not (==None).
Or course, you can always easily get rid of xsi:nil if you wish so:
>>> for elt in root.iter(): elt.attrib.pop('{http://www.w3.org/2001/XMLSchema-instance}nil', None)
Holger
--
Nur bis 31.05.: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und
Telefonanschluss nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
More information about the lxml-dev
mailing list