我正在尝试编写一些代码,这些代码将在文章的 XML 文件中搜索标签中包含的特定 DOI。当它找到正确的 DOI 时,我希望它访问<title>
与<abstract>
该 DOI 关联的文章的文本。
我的 XML 文件是这种格式:
<root>
<article>
<number>
0
</number>
<DOI>
10.1016/B978-0-12-381015-1.00004-6
</DOI>
<title>
The patagonian toothfish biology, ecology and fishery.
</title>
<abstract>
lots of abstract text
</abstract>
</article>
<article>
...All the article tags as shown above...
</article>
</root>
我希望脚本能够找到 DOI 为 10.1016/B978-0-12-381015-1.00004-6 的文章(例如),然后让我能够访问相应标签中的<title>
和标签。<abstract>
<article>
到目前为止,我已经尝试从这个问题中调整代码:
from xml.dom import minidom
datasource = open('/Users/philgw/Dropbox/PW-Honours-Project/Code/processed.xml')
xmldoc = minidom.parse(datasource)
#looking for: 10.1016/B978-0-12-381015-1.00004-6
matchingNodes = [node for node in xmldoc.getElementsByTagName("DOI") if node.firstChild.nodeValue == '10.1016/B978-0-12-381015-1.00004-6']
for i in range(len(matchingNodes)):
DOI = str(matchingNodes[i])
print DOI
但我不完全确定我在做什么!
谢谢你的帮助。