[lxml-dev] Getting around namespaces
Stefan Behnel
stefan_ml at behnel.de
Sat Jan 24 03:30:35 CET 2009
Hi,
Ross Vandegrift wrote:
> On Fri, Jan 23, 2009 at 09:23:05PM +0100, Stefan Behnel wrote:
>> you can use local-name()
>
> Wow, I had no idea that function existed. It merits a single mention
> in Learning XML and barely a reference entry in Mastering XSLT.
The only XSLT book I ever 'read' was the XSLT reference by Michael Kay.
Even the first edition was so incredibly complete, I never needed anything
else.
> Do you know if anyone has done any work on transforming general XML
> into a Python dict?
I'm not quite sure how you want the transformation to work. If all you want
is a dict of dicts, then
def recursive_dict(element):
return element.tag, \
dict(map(recursive_dict, element)) or element.text
might already do the job for you (I just made that up, but it looks so
neat, I should put it into the FAQ). You should also take a look at
lxml.objectify which simplifies the work with Python data types in XML.
Stefan
More information about the lxml-dev
mailing list