Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using lxml, can the XML be rendered without namespace attributes?

Tags:

python

lxml

I am generating some XML with lxml and getting nodes generated like this:

<QBXML 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"
py:pytype="TREE">

and:

<MaxReturned py:pytype="int">

These custom attributes are killing Quickbooks' parser. Can I get LXML to render without the custom stuff?

like image 331
Randy Syring Avatar asked Feb 22 '11 22:02

Randy Syring


Video Answer


1 Answers

Looks like the following take care of it:

objectify.deannotate(root, xsi_nil=True)
etree.cleanup_namespaces(root)

or, if using lxml >= 2.3.2 (thanks @Pedru):

objectify.deannotate(root, cleanup_namespaces=True, xsi_nil=True)
like image 173
Randy Syring Avatar answered Nov 15 '22 15:11

Randy Syring