0

Hi I using XmlTextReader to read policy files generated by the iPhone Configuration Utility 3.6 when the reader reaches the doctype element it will hang up for about 15-20 seconds. This is a huge problem for me because i need to read 60 files at a time and it reads each file 3 times. Here is some code I have and a sample file that you can use to repeat the problem.

private int findStart(String d)
    {
        Boolean StartLooking = false;
        using (XmlTextReader xr = new XmlTextReader(d))
        {
            while (xr.Read())
            {
                if (xr.NodeType.Equals(XmlNodeType.Element) && xr.Name.Equals("dict") && !StartLooking)
                    StartLooking = true;
                else if (xr.NodeType.Equals(XmlNodeType.Element) && xr.Name.Equals("dict") && StartLooking)
                    return xr.LineNumber;
            }
            xr.Close();
        }
        return -1;
    }

XML File: AdvancedPayload.mobileconfig (Dropboxlink)

Please reply if you know why this hangup occurs. Thanks

Josh Starrett
  • 149
  • 1
  • 10
  • What is the DOCTYPE look like? It looks to me that the doctype has a reference to an external DTD and your app is actually downloading the external DTD from the web. Can it be the case? Does the Xml (or you) need the DTD at all? AFAIR you could turn off DTD processing. Also consider using XmlReader over XmlTextReader - you can find more here: http://blogs.msdn.com/b/xmlteam/archive/2011/10/08/the-world-has-moved-on-have-you-xml-apis-you-should-avoid-using.aspx – Pawel Oct 04 '12 at 18:03
  • I actually am using the reader for formatting reason's only so ignoring dtd isn't a problem. This also fixed the hangup I was getting. Thank you! – Josh Starrett Oct 04 '12 at 18:32
  • FYI, unless you're stuck with .NET 1.1, you should not use `new XmlTextReader()`. Use `XmlReader.Create()` instead. – John Saunders Oct 04 '12 at 19:32

2 Answers2

0

What is the DOCTYPE look like? It looks to me that the doctype has a reference to an external DTD and your app is actually downloading the external DTD from the web. Can it be the case? Does the Xml (or you) need the DTD at all? AFAIR you could turn off DTD processing if you don't need it.

Pawel
  • 31,342
  • 4
  • 73
  • 104
0

Use XmlTextReader.DtdProcessing=DtdProcessing.Ignore;

Lukas Kabrt
  • 5,441
  • 4
  • 43
  • 58