2016-07-18 4 views
1

コードを使用して巨大な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&uuml;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&igrave;</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コマンドやコードを使用して)もうれしいです。ケースの数が多くない場合は、手動で修正することができます。

答えて

2

解決方法は次のとおりです。破損したXMLを手動で修復します。

任意の検証エラーが発生した場合に自動的に適用できる一般的な修復方法はありません。自動的にカバーされる簡単なケースがあるかもしれませんが、一般的に検証エラーに対処する方法は複数あります。通常は、どちらが適切であるかを判断し、XMLを手動で修復します(または、無効なXMLを生成したアップストリームシステムを修正します)。

次に、もう一度検証し、それ以降の問題に対処します。このサイクルは、検証エラーがなくなるまで繰り返されます(プログラミング言語の構文上の問題の修復によく似ています)。

関連する問題