我正在尝试从这个XML文档中提取数据,并将输出设置为一个列表:
例如:
['10-Yard Fight (USA, Europe)', '1942 (Japan, USA)', .......]
我只能想办法把它列成许多独立的清单。你知道吗
例如:
['10-Yard Fight (USA, Europe)']
['1942 (Japan, USA)']
[.......]
XML示例:
<?xml version="1.0"?>
<menu>
<header>
<listname>Nintendo Entertainment System</listname>
<id>003</id>
<lastlistupdate>10/16/2014</lastlistupdate>
<listversion>1.1 Final</listversion>
<manufacturer>Nintendo</manufacturer>
<media>
<artwork></artwork>
<video></video>
</media>
<exporterversion>HyperList XML Exporter Version 1.3 Copywrite (c) 2009-2011 William Strong</exporterversion>
</header>
<game name="10-Yard Fight (USA, Europe)" index="true" image="1" id="0034232">
<description>10-Yard Fight (USA, Europe)</description>
<cloneof></cloneof>
<crc>3D564757</crc>
<manufacturer>Nintendo</manufacturer>
<year>1985</year>
<genre>Football/Sports</genre>
<rating>HSRS - GA (General Audience)</rating>
<enabled>Yes</enabled>
</game>
<game name="1942 (Japan, USA)" index="" image="">
<description>1942 (Japan, USA)</description>
<cloneof></cloneof>
<crc>171251E3</crc>
<manufacturer>Capcom</manufacturer>
<year>1986</year>
<genre>Shoot-'Em-Up</genre>
<rating>HSRS - GA (General Audience)</rating>
<enabled>Yes</enabled>
</game>
<game name="1943 - The Battle of Midway (USA)" index="" image="">
<description>1943 - The Battle of Midway (USA)</description>
<cloneof></cloneof>
<crc>12C6D5C7</crc>
<manufacturer>Capcom</manufacturer>
<year>1988</year>
<genre>Shoot-'Em-Up</genre>
<rating>HSRS - GA (General Audience)</rating>
<enabled>Yes</enabled>
</game>
</menu>
我的示例Python代码
from xml.dom import minidom
def databaseGameExtraction(xml):
xmldoc = minidom.parse(xml)
games = xmldoc.getElementsByTagName('game')
for game in games:
romKey = game.attributes['name']
roms = [romKey.value]
print(roms)
return roms
databaseGameExtraction('Nintendo Entertainment System.xml')
另外,我想得到'任天堂娱乐系统'的价值,以得到回报,以及。你知道吗
在理想情况下,当从另一个函数调用时,该函数将以列表形式返回rom,并以列表形式返回系统名称。你知道吗
谢谢你
您需要从XML以迭代方式构建
roms
列表:或者最好写成list-comprehension:
您还可以使用以下方法提取“任天堂娱乐系统”:
这给我们留下了:
我想你需要
相关问题 更多 >
编程相关推荐