我是Python新手。现在我必须用Python替换XML文件中的许多值。XML的示例片段是:
<gmd:extent>
<gmd:EX_Extent>
<gmd:description gco:nilReason="missing">
<gco:CharacterString />
</gmd:description>
<gmd:geographicElement>
<gmd:EX_GeographicBoundingBox>
<gmd:westBoundLongitude>
<gco:Decimal>112.907</gco:Decimal>
</gmd:westBoundLongitude>
<gmd:eastBoundLongitude>
<gco:Decimal>158.96</gco:Decimal>
</gmd:eastBoundLongitude>
<gmd:southBoundLatitude>
<gco:Decimal>-54.7539</gco:Decimal>
</gmd:southBoundLatitude>
<gmd:northBoundLatitude>
<gco:Decimal>-10.1357</gco:Decimal>
</gmd:northBoundLatitude>
</gmd:EX_GeographicBoundingBox>
</gmd:geographicElement>
</gmd:EX_Extent>
</gmd:extent>
我要做的是用一个指定的值替换这些十进制值,即112.907。在
^{pr2}$我尝试了一些方法,但是没有一个能满足我的假设,即名称空间前缀gmd和gco是困难的。在
请帮帮我。提前谢谢!在
干杯,亚历克斯
如果不在顶部添加虚假的名称空间声明,就无法让lxml处理xml,所以下面是输入的外观
我假设你有两个列表一个是当前值,一个是新值
旧=[112.907158.96,-54.7539,-10.1357] 新=[1,2,3,4] d=dict(zip(旧,新))
这是完整的代码
^{pr2}$下面是输出的样子
相关问题 更多 >
编程相关推荐