Saving XML files using ElementTree

前端 未结 4 995
南笙
南笙 2020-11-30 06:28

I\'m trying to develop simple Python (3.2) code to read XML files, do some corrections and store them back. However, during the storage step ElementTree adds this n

4条回答
  •  误落风尘
    2020-11-30 06:50

    If you try to print the root, you will see something like this: http://www.host.domain/path/to/your/xml/namespace}RootTag' at 0x0000000000558DB8>

    So, to avoid the ns0 prefix, you have to change the default namespace before parsing the XML data as below:

    ET.register_namespace('', "http://www.host.domain/path/to/your/xml/namespace")
    

提交回复
热议问题