【发布时间】:2013-11-14 16:17:39
【问题描述】:
我有一个 xml 文件 - 这是一个 sn-p..
<gmd_fileIdentifier>
<gco_CharacterString>{0328cb65-b564-495a-b17e-e49e04864ab7}</gco_CharacterString>
</gmd_fileIdentifier>
<gmd_identifier>
<gmd_RS_Identifier>
<gmd_authority gco_nilReason="missing" />
<gmd_code>
<gco_CharacterString>0000</gco_CharacterString>
</gmd_code>
<gmd_codeSpace xmlns:gml="http://www.opengis.net/gml" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<gco_CharacterString>test</gco_CharacterString>
</gmd_codeSpace>
</gmd_RS_Identifier>
</gmd_identifier>
我要做的是将标签中当前的值 0000 更改为 gmd_fileIdentifier 字符串 {0328cb65-b564-495a-b17e-e49e04864ab7}。
我可以使用以下 python 代码访问这些值,但是如何设置该值? 当前代码
import os, sys
from lxml import etree
myXML = r"D:\test.xml"
tree = etree.parse(myXML)
root = tree.getroot()
root.xpath("//gmd_fileIdentifier/gco_CharacterString/text()")
print fileID
code = root.xpath("//gmd_identifier/gmd_RS_Identifier/gmd_code/gco_CharacterString/text()")
print code
谢谢
【问题讨论】: