XML 文件如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MINiML
xmlns="http://www.ncbi.nlm.nih.gov/geo/info/MINiML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ncbi.nlm.nih.gov/geo/info/MINiML http://www.ncbi.nlm.nih.gov/geo/info/MINiML.xsd"
version="0.5.0" >
<Contributor iid="contrib1">
<Person><First>ENCODE</First><Last>DCC</Last></Person>
<Email>encode-help@lists.stanford.edu</Email>
<Organization>ENCODE DCC</Organization>
<Address>
<Line>300 Pasteur Dr</Line>
<City>Stanford</City>
<State>CA</State>
<Zip-Code>94305-5120</Zip-Code>
<Country>USA</Country>
</Address>
</Contributor>
</MINiML>
这是我ElementTree
在 Python 中使用的方法:
import xml.etree.cElementTree as ET
tree=ET.parse("the_file_above.xml")
root = tree.getroot()
for c in root:
print c.tag, c.attrib
它返回:
{http://www.ncbi.nlm.nih.gov/geo/info/MINiML}Contributor {'iid': 'contrib1'}
的值c.tag
是'{http://www.ncbi.nlm.nih.gov/geo/info/MINiML}Contributor'
,这是我预期的Contributor
。我不确定标签中的长网址是如何混合的。有人对此有想法吗?