我试图用python2.7和xml.etree.ElementTree.
下面是我用来遍历XML的循环。
prefixes=['conn','dummy']
for datasource in root.findall('.//datasource'):
for relation in datasource.findall('.//relation'):
if 'connection' in relation.attrib:
if relation.attrib['connection'].startswith(tuple(prefixes)):
sql = SQL(relation.text)
if sql.isCustom() is True:
return sql.findTables()
else:
print(relation.attrib['table'])
return relation.attrib['table']
<datasources>
<datasource>
<connection>
<relation connection="conn.dbe" table="table1">
<datasource>
<connection>
<relation connection="conn.abc" table="table2">
我尝试过使用iterall和findall('.//*relationship')作为匹配模式,但是到目前为止还没有任何结果。