0

这是我的方法

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 文件。

调试甚至没有命中 in collection = new incollection 所以没有错误

4

1 回答 1

2

Firefox 报告此错误:

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

于 2013-10-12T08:32:58.433 回答