Python: Update XML-file using ElementTree while conserving layout as much as possible

后端 未结 4 967
天命终不由人
天命终不由人 2021-01-04 03:36

I have a document which uses an XML namespace for which I want to increase /group/house/dogs by one: (the file is called houses.xml)



        
4条回答
  •  伪装坚强ぢ
    2021-01-04 04:20

    etree from lxml provides this feature.

    1. elementTree.write('houses2.xml',encoding = "UTF-8",xml_declaration = True) helps you in not omitting the declaration

    2. While writing into the file it does not change the namespaces.

    http://lxml.de/parsing.html is the link for its tutorial.

    P.S : lxml should be installed separately.

提交回复
热议问题