C# XmlTextReader, Ignoring DTD Processing

2.2k Views Asked by At

I have this method:

public void XmlTagCounter(string xmlPath, List<string> elements, List<int> elemCount)
{
    XmlTextReader reader = new XmlTextReader(xmlPath);

    try
    {
        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                if (elements.Exists(x => x == reader.Name))
                {
                    string curElem = elements.Find(x => x == reader.Name);
                    int index = elements.IndexOf(curElem);
                    elemCount[index]++;
                }

                else
                {
                    elements.Add(reader.Name);
                    elemCount.Add(1);
                }
            }
        }
    }

    finally
    {
        reader.Close();
    }
}

I count all the tags used in an XML. But I have some problem, I want to ignore the DTD Processing. Because it always return some exception because of the missing DTD on the pathFolder, I don't want to catch that exception. How can I ignore the DtdProcessing in XmlTextreader?

Thanks for all of your help.

0

There are 0 best solutions below