无法访问 XML 数据结构中的"Data":<名称属性>数据 </Name>



我需要访问"数据"下面的XML数据结构:

<Name Attributes> Data </Name>

使用正常的Python解析.attrib,我只能访问"属性"但我需要"数据">

你知道这个数据结构是什么意思吗?我如何访问"数据"?与Python .

谢谢!

根据您的示例,它应该是name.text或您想为此name.text = "new Data"分配新值

的例子:

import xml.etree.ElementTree as ET
tree = ET.parse("some-random-file")
parent = tree.getroot()
name = parent.find(".//name")
name.text = "new Data"
参考

最新更新