1

私は次のようなロジックを持っています:</p>

for root, dirs, files in os.walk(os.getcwd()):
    if "info.xml" in files:
        root = lxml.etree.parse("%s/info.xml" % root)
        tag = root.xpath("/info/tagname")[0].text

info.xml現在のパスの非常に深いものを解析すると、次のエラー メッセージが表示されます。

    Traceback (most recent call last):
  File "/home/work/mergefile.py", line 365, in <module>
  File "/home/work/mergefile.py", line 344, in merge_ejb_files
  File "/home/work/mergefile.py", line 63, in __init__
  File "/home/work/mergefile.py", line 78, in _parse_info2doc
  File "lxml.etree.pyx", line 2698, in lxml.etree.parse (src/lxml/lxml.etree.c:49590)
  File "parser.pxi", line 1491, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:71205)
  File "parser.pxi", line 1520, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:71488)
  File "parser.pxi", line 1420, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:70583)
  File "parser.pxi", line 975, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:67736)
  File "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:63820)
  File "parser.pxi", line 625, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:64741)
  File "parser.pxi", line 563, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:64056)
IOError: Error reading file '/home/work/ci/case/dc_daily/dc/213577/223922/223958/792536/info.xml': failed to load external entity "/home/work/ci/case/dc_daily/dc/213577/223922/223958/792536/info.xml"

しかし、ファイル"/home/work/ci/case/dc_daily/dc/213577/223922/223958/792536/info.xml"は存在し、ipython IDEの下でlxmlで解析できます

何が問題か知っていますか?ご存知の方、お助けください!ありがとうございました!

4

1 に答える 1

0

上記の私のコメントによると、これが私の解決策です。読み取り用にファイルを開いていますが、すぐに閉じているので、1024 ファイルの制限に達しません。

import lxml.etree as etree
for root,dirs,files in os.walk(os.getcwd()):
    if "info.xml" in files:
        with open('%s/info.xml'%root) as processfile: #use 'rb' if necessary
            xml = etree.parse(processfile)
            tag = root.xpath("/info/tagname")[0].text
于 2011-08-06T04:28:50.613 に答える