我正在尝试使用Biopython的Bio Entrez解析函数解析PubMed Central XML文件。这是我到目前为止所尝试的:
from Bio import Entrez
for xmlfile in glob.glob ('samplepmcxml.xml'):
print xmlfile
fh = open (xmlfile, "r")
read_xml (fh, outfp)
fh.close()
def read_xml (handle, outh):
records = Entrez.parse(handle)
for record in records:
print record
我收到以下错误:
Traceback (most recent call last):
File "3parse_info_from_pmc_nxml.py", line 78, in <module>
read_xml (fh, outfp)
File "3parse_info_from_pmc_nxml.py", line 10, in read_xml
for record in records:
File "/usr/lib/pymodules/python2.6/Bio/Entrez/Parser.py", line 137, in parse
self.parser.Parse(text, False)
File "/usr/lib/pymodules/python2.6/Bio/Entrez/Parser.py", line 165, in startNamespaceDeclHandler
raise NotImplementedError("The Bio.Entrez parser cannot handle XML data that make use of XML namespaces")
NotImplementedError: The Bio.Entrez parser cannot handle XML data that make use of XML namespaces
我已经下载了archivearticle.dtd文件。是否还需要安装其他可描述PMC文件架构的DTD文件?有没有人成功使用Bio Entrez函数或任何其他方法来解析PMC文章?
感谢您的帮助!
答案 0 :(得分:1)
使用其他解析器,例如minidom
from xml.dom import minidom
data = minidom.parse("pmc_full.xml")
现在,根据您想要提取的数据,深入了解XML并享受乐趣:
for title in data.getElementsByTagName("article-title"):
for node in title.childNodes:
if node.nodeType == node.TEXT_NODE:
print node.data