Saving XML files using ElementTree

前端 未结 4 985
南笙
南笙 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 07:03

    You need to register all your namespaces before you parse xml file.

    For example: If you have your input xml like this and Capabilities is the root of your Element tree.

    
    

    Then you have to register all the namespaces i.e attributes present with xmlns like this:

    ET.register_namespace('', "http://www.opengis.net/wmts/1.0")
    ET.register_namespace('ows', "http://www.opengis.net/ows/1.1")
    ET.register_namespace('xlink', "http://www.w3.org/1999/xlink")
    ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
    ET.register_namespace('gml', "http://www.opengis.net/gml")
    

提交回复
热议问题