Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用python解析xml文件后获取属性值?_Python_Python 3.x_Xml - Fatal编程技术网

如何在使用python解析xml文件后获取属性值?

如何在使用python解析xml文件后获取属性值?,python,python-3.x,xml,Python,Python 3.x,Xml,我有一个xml文件,当我使用下面的python代码解析它时。这是它打印的结果: columnInfo {'class': 'com.manu.webservices.metadata.ColumnBean', 'columnName': 'Employee', 'schemaName': 'Workers', 'tableName': 'humanResource'} 我想从tableName打印人力资源 Result Expected: humanResource 我尝试的是: impor

我有一个xml文件,当我使用下面的python代码解析它时。这是它打印的结果:

columnInfo {'class': 'com.manu.webservices.metadata.ColumnBean', 'columnName': 'Employee', 'schemaName': 'Workers', 'tableName': 'humanResource'}
我想从tableName打印人力资源

Result Expected:
humanResource
我尝试的是:

import xml.etree.ElementTree as ET
tree = ET.parse('file.xml')
root = tree.getroot()

for child in root:
    print (child.tag, child.attrib)

child.attrib['tableName']
为什么这个问题被标记为“regex”?