Randy Syring Randy Syring - 1 year ago 167
Python Question

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

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"


<MaxReturned py:pytype="int">

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

Answer Source

Looks like the following take care of it:

objectify.deannotate(root, xsi_nil=True)

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

objectify.deannotate(root, cleanup_namespaces=True, xsi_nil=True)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download