Python pretty XML printer with lxml

前端 未结 5 558
一整个雨季
一整个雨季 2020-11-28 09:37

After reading from an existing file with \'ugly\' XML and doing some modifications, pretty printing doesn\'t work. I\'ve tried etree.write(FILE_NAME, pretty_print=True

5条回答
  •  北海茫月
    2020-11-28 10:09

    I am not sure why other answers did not mention this. If you want to obtain the root of the xml there is a method called getroot(). I hope I answered your question (though a little late).

    tree = et.parse(xmlFile)
    root = tree.getroot()
    

提交回复
热议问题