2013-10-12 112 views
0

這是我的方法XMLReader可以跳過特定的行

private void ParseXML() 
{ 
    int pubid = 1; 

    settings.DtdProcessing = DtdProcessing.Parse; 
    using (reader = XmlReader.Create(FileName, settings)) 
    { 
     while (reader.Read()) 
     { 
      if (reader.IsStartElement()) 
      { 
       switch (reader.Name.Trim().ToLower()) 
       { 

        case "book": 
         book = new Book(); 
         book.Pubid = pubid; 
         book.Pubtype = "book"; 
         book.Pubkey = reader.GetAttribute("key"); 
         ParseBook(reader, book); 
         pubid++; 
         break; 

        case "article": 
         article = new Article(); 
         article.Pubid = pubid; 
         article.Pubkey = reader.GetAttribute("key"); 
         article.Pubtype = "article"; 
         ParseArticle(reader, article); 
         pubid++; 
         break; 

        case "incollection": 
         incollection = new Incollection(); 
         incollection.Pubid = pubid; 
         incollection.Pubkey = reader.GetAttribute("key"); 
         ParseIncollection(reader, incollection); 
         pubid++; 
         break; 

        case "inproceedings": 
         inproceeding = new Inproceedings(); 
         inproceeding.Pubid = pubid; 
         inproceeding.Pubtype = "inproceeding"; 
         inproceeding.Pubkey = reader.GetAttribute("key"); 
         ParseInproceedings(reader, inproceeding); 
         pubid++; 
         break; 
       } 
      } 
     } 
    } 
} 

我解析這個文件。 http://dblp.uni-trier.de/xml/

但是,我檢查了與其他解析器的xml,它似乎incollections元素是在xml中。

但是,當我運行這段代碼時,我的情況「incollection」未被觸發。其他工作正常。

這是1.2Gb的xml文件。

調試甚至不打在收集=新incollection所以沒有錯誤

+0

的讀取請改善這一點:1.包含XML有足夠的報價(鏈接有三個XML文件,其中兩個是用於快速瀏覽過大)。 2.調試顯示什麼? – Richard

+0

@Richard我編輯了這個問題 – aceminer

+0

這樣會好一點,但是要讓問題中的信息內聯(以及完整的,即可編譯的)代碼顯示問題遠遠好得多。 – Richard

回答

2

火狐報告這個錯誤:

XML Parsing Error: undefined entity 

Location: http://dblp.uni-trier.de/xml/dblp.xml 
Line Number 26, Column 37: 
<journal>technical Report 248, ETH Z&uuml;rich, Dept. of Computer Science</journal> 
------------------------------------^ 

錯誤字符ü

&uuml; 

也許你應該考慮使用允許符號的CDATA ...

<![CDATA[ 
    This is some text with ampersands & other funny characters. >> 
]]> 

編輯:有這個文件reading-xml-with-an-into-c-sharp-xmldocument-object