【发布时间】:2011-09-02 17:51:14
【问题描述】:
可能重复:
When using lxml, can the XML be rendered without namespace attributes?
如何从lxml.objectify.ObjectifiedElement 中去除 python 属性?
示例:
In [1]: from lxml import etree, objectify
In [2]: foo = objectify.Element("foo")
In [3]: foo.bar = "hi"
In [4]: foo.baz = 1
In [5]: foo.fritz = None
In [6]: print etree.tostring(foo, pretty_print=True)
<foo 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">
<bar py:pytype="str">hi</bar>
<baz py:pytype="int">1</baz>
<fritz xsi:nil="true"/>
</foo>
我希望输出看起来像:
<foo>
<bar>hi</bar>
<baz>1</baz>
<fritz/>
</foo>
【问题讨论】:
标签: python formatting lxml objectify elementtree