1

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.

jomsk1e
  • 3,585
  • 7
  • 34
  • 59
  • http://social.msdn.microsoft.com/forums/en-US/xmlandnetfx/thread/b8b062c8-d0d0-498b-a9a5-76dc7d72cf9a/ – Yuck Oct 16 '12 at 03:13
  • thanks Yuck for that link. I found the answer now. – jomsk1e Oct 16 '12 at 03:24
  • here's what I did: XmlTextReader reader = new XmlTextReader(xmlPath) { DtdProcessing = DtdProcessing.Ignore, XmlResolver = null }; – jomsk1e Oct 16 '12 at 03:25
  • Consider using XmlReader instead of XmlTextReader. Here is why: http://blogs.msdn.com/b/xmlteam/archive/2011/10/08/the-world-has-moved-on-have-you-xml-apis-you-should-avoid-using.aspx. If you use XmlReader DTD processing is disabled by default. – Pawel Oct 16 '12 at 04:45

0 Answers0