【问题标题】:Parsing PubMed Central XML using Biopython Bio Entrez parse使用 Biopython Bio Entrez 解析 PubMed Central XML
【发布时间】:2014-08-02 00:22:55
【问题描述】:

我正在尝试使用 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 文件。是否需要安装任何其他 DTD 文件来描述 PMC 文件的架构?有没有人成功使用过Bio Entrez函数或者其他方法解析PMC文章?

感谢您的帮助!

【问题讨论】:

    标签: python xml-parsing dtd biopython


    【解决方案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
    

    【讨论】:

    • 嗨@xbello,感谢您的快速回复。我们如何通过属性访问节点?例如PMC156895。我还在努力熟悉模块和 xml 结构。
    • 一旦你得到带有[x for x in getElementsByTagName("article-id")]或其他东西的元素,你可以做一个x.getAttribute("pub-id-type")。也许这是深入 XML 的更好链接:docs.python.org/2/library/xml.dom.html,在Element Objects 部分中查看所有带有Attribute 的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 2012-11-13
    • 2013-11-07
    • 1970-01-01
    相关资源
    最近更新 更多