【问题标题】:XMLReader skips particular rowXMLReader 跳过特定行
【发布时间】:2023-03-03 04:54:22
【问题描述】:

这是我的方法

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 所以没有错误

【问题讨论】:

  • 请改进: 1. 包含足够的 XML 引用(该链接包含三个 XML 文件,其中两个太大,无法快速查看)。 2.调试显示什么?
  • @Richard 我已经编辑了问题
  • 这有点好,但在问题中嵌入信息(连同已完成的,即可编译的)代码来显示问题要好得多。

标签: c# .net xml sax


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2019-01-19
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多