使用lxml库在Python中解析xml时出错

时间:2021-12-21 15:48:24

I am not able to use the pretty_print argument to print the xml. Any idea what could be wrong ?

我无法使用pretty_print参数来打印xml。知道什么可能是错的吗?

I am attaching the code sample as well.

我也附上了代码示例。

Thanks

谢谢

import xml.etree.cElementTree as etree
import os

def main():

    root = etree.Element("root")

    Series = etree.SubElement(root, "Element")

    SeriesID = etree.SubElement(Series, "Index")
    SeriesID.text = "80379"


    #print str(etree)
    #print(etree.tostring(root, pretty_print=True))

    print(etree.tostring(root))

if __name__ == "__main__":
    main()

1 个解决方案

#1


1  

xml.etree.ElementTree.tostring() does not have a pretty_print parameter.

xml.etree.ElementTree.tostring()没有pretty_print参数。

lxml.etree.tostring() on the other hand has a pretty_print parameter.

另一方面,lxml.etree.tostring()有一个pretty_print参数。

#1


1  

xml.etree.ElementTree.tostring() does not have a pretty_print parameter.

xml.etree.ElementTree.tostring()没有pretty_print参数。

lxml.etree.tostring() on the other hand has a pretty_print parameter.

另一方面,lxml.etree.tostring()有一个pretty_print参数。