コードを使用して巨大なxmlファイルを解析しています。hereが問題なく動作します。しかし、いくつかのケースでは、親要素が欠落しています。lxmlを使用してXMLで不足しているタグを処理する
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE dblp SYSTEM "dblp.dtd">
<dblp>
<article mdate="2011-01-11" key="journals/acta/Ernst77">
<author>George W. Ernst</author>
<title>Rules of Inference for Procedure Calls.</title>
<journal>Acta Inf.</journal>
<volume>8</volume>
<year>1977</year>
<pages>145-152</pages>
<url>db/journals/acta/acta8.html#Ernst77</url>
<ee>http://dx.doi.org/10.1007/BF00289246</ee>
</article>
<article mdate="2011-01-11" key="journals/acta/Pfaff83">
<author>Günther E. Pfaff</author>
<title>The Construction of Operator Interfaces Based on Logical Input Devices.</title>
<pages>151-166</pages>
<year>1983</year>
<volume>19</volume>
<journal>Acta Inf.</journal>
<url>db/journals/acta/acta19.html#Pfaff83</url>
<ee>http://dx.doi.org/10.1007/BF00264473</ee>
</article>
<article mdate="2011-01-11" key="journals/acta/EngelfrietV88">
<author>Joost Engelfriet</author>
<author>Heiko Vogler</author>
<title>High Level Tree Transducers and Iterated Pushdown Tree Transducers.</title>
<pages>131-192</pages>
<year>1988</year>
<volume>26</volume>
<journal>Acta Inf.</journal>
<number>1/2</number>
<url>db/journals/acta/acta26.html#EngelfrietV88</url>
<ee>http://dx.doi.org/10.1007/BF02915449</ee>
</article>
<author>Antonio Gullì</author>
<title>Clustering and ranking for web information retrieval: methodologies for searching the web.</title>
<year>2008</year>
<school>University of Pisa</school>
<pages>1-137</pages>
<isbn>978-3-8364-5657-9</isbn>
<ee>http://d-nb.info/987753223</ee>
</dblp>
最後のレコードは、開始タグと終了タグ<article>
が欠落しています。ここでは一例です。
コード(リンクで提供されています)のエラーは、forループfor event, element in context
にあるextract_paper_elements
の機能から発生します。ここにエラーがあります:
Element dblp content does not follow the DTD, expecting (article | inproceedings | proceedings | book | incollection | phdthesis | mastersthesis | www)*, got (article article article author title year school pages isbn ee), line 47, column 12
このような場合の解決策はありますか? 私はこれらのケースを見つけるための解決策(bashコマンドやコードを使用して)もうれしいです。ケースの数が多くない場合は、手動で修正することができます。