2013-10-12 62 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