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 に答える