2024-06-27 09:26:20 发布
网友
我在Python中使用ElementTree来解析一个XML文件,以找到标记contentType的内容。在
ElementTree
contentType
这是Python的一行:
extensionType = ET.parse("src/" + str(filename)).find('contentType')
下面是XML:
我做错什么了?在
谢谢!在
到目前为止,您只是在解析xml文件。这就是使用xpath获取元素的方法(注意如何使用给定的xml名称空间xmlns)
xmlns
import xml.etree.cElementTree as ET tree = ET.parse('test.xml') root = tree.getroot() xmlns = {'soap': '{http://soap.sforce.com/2006/04/metadata}'} ct_element = root.find('.//{soap}contentType'.format(**xmlns)) print(ct_element.text)
到目前为止,您只是在解析xml文件。这就是使用xpath获取元素的方法(注意如何使用给定的xml名称空间
xmlns
)相关问题 更多 >
编程相关推荐