English 中文(简体)
我如何看待某一轴心的案文。
原标题:How can I view a text representation of an lxml element?
  • 时间:2009-10-14 17:48:03
  •  标签:

If I m parsing an XML document using lxml, is it possible to view a text representation of an element? I tried to do :

print repr(node)

但产出

<Element obj at b743c0>

我可以怎样看待在XML档案中存在的问题? 是否有某种<条码>至_xml方法或东西?

最佳回答

http://lxml.de/tutorial.html#serialisation”rel=“noreferer” http://lxml.de/tutorial.html#serialisation

>>> root = etree.XML( <root><a><b/></a></root> )

>>> etree.tostring(root)
b <root><a><b/></a></root> 

>>> print(etree.tostring(root, xml_declaration=True))
<?xml version= 1.0  encoding= ASCII ?>
<root><a><b/></a></root>

>>> print(etree.tostring(root, encoding= iso-8859-1 ))
<?xml version= 1.0  encoding= iso-8859-1 ?>
<root><a><b/></a></root>

>>> print(etree.tostring(root, pretty_print=True))
<root>
  <a>
    <b/>
  </a>
</root>
问题回答

暂无回答




相关问题
热门标签