Array Bounds Error in SetElementValues of XmlTextReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Exception: Index was outside the bounds of the array
at System.Xml.XmlTextReader.SetElementValues(
at System.Xml.XmlTextReader.ParseElement(
at System.Xml.XmlTextReader.Read(
at xmlReaderApp.Class1.Main(String[] args

The program handles more than 88 million Element XmlNodeType items and then throws the exception shown above. Could this be an issue

Here is the program..

using System
using System.Xml
using System.Collections

// This program reads an ASCII file of XML elements
// The output is a list of unique NODE TYPEs
// For example, <head> produces head in the output
// There is no validation of the XML

namespace xmlReaderAp

/// <summary
/// Summary description for Class1
/// </summary
class Class

/// <summary
/// The main entry point for the application
/// </summary
[STAThread

static void Main(string[] args

int symbolNumber=0
ArrayList arrayList = new ArrayList()
XmlTextReader xmlReader = new XmlTextReader(@"c:\1.xml")
tr

xmlReader.MoveToContent(); // Get beyond the DTD which we don't care abou

catch (Exception e

Console.WriteLine("Exception: " + e.Message); // handle undefined DT

try

while (xmlReader.Read())

symbolNumber++
if (symbolNumber % 100000 == 0
Console.WriteLine(symbolNumber)
switch (xmlReader.NodeType)

case XmlNodeType.Element
// Console.Write("<{0}>", xmlReader.Name)
bool bDoAdd = true
foreach (String memberofArrayList in arrayList
if (memberofArrayList.Equals(xmlReader.Name)

bDoAdd = false
break

if (bDoAdd
arrayList.Add(xmlReader.Name)
break
case XmlNodeType.Text
// Console.Write(xmlReader.Value)
break
case XmlNodeType.CDATA
// Console.Write("<![CDATA[{0}]]>", xmlReader.Value)
break
case XmlNodeType.ProcessingInstruction
// Console.Write("<?{0} {1}?>", xmlReader.Name, xmlReader.Value)
break
case XmlNodeType.Comment
// Console.Write("<!--{0}-->", xmlReader.Value)
break
case XmlNodeType.XmlDeclaration
// Console.Write("<?xml version='1.0'?>")
break
case XmlNodeType.Document
break
case XmlNodeType.DocumentType
// Console.Write("<!DOCTYPE {0} [{1}]", xmlReader.Name, xmlReader.Value)
break
case XmlNodeType.EntityReference
// Console.Write(xmlReader.Name)
break
case XmlNodeType.EndElement
// Console.Write("</{0}>", xmlReader.Name)
break



xmlReader.Close()
foreach (String memberofArrayList in arrayList
Console.WriteLine(memberofArrayList)
Console.WriteLine("This program has terminated.")

catch(Exception e)

xmlReader.Close()
Console.WriteLine("Exception: " + e.Message)
Console.WriteLine(e.StackTrace)
Console.WriteLine(e.Source)
foreach (String memberofArrayList in arrayList
Console.WriteLine(memberofArrayList)
Console.WriteLine("This program has terminated.")
return
 
re-run this under the debugger. set the debugger to break on all exceptions
(ctrl+alt+E). it will stop at the line of the error. you can take it from
there.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
William McIlroy said:
Exception: Index was outside the bounds of the array.
at System.Xml.XmlTextReader.SetElementValues()
at System.Xml.XmlTextReader.ParseElement()
at System.Xml.XmlTextReader.Read()
at xmlReaderApp.Class1.Main(String[] args)

The program handles more than 88 million Element XmlNodeType items and
then throws the exception shown above. Could this be an issue?

Here is the program...

using System;
using System.Xml;
using System.Collections;

// This program reads an ASCII file of XML elements.
// The output is a list of unique NODE TYPEs.
// For example, <head> produces head in the output.
// There is no validation of the XML.

namespace xmlReaderApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]

static void Main(string[] args)
{
int symbolNumber=0;
ArrayList arrayList = new ArrayList();
XmlTextReader xmlReader = new XmlTextReader(@"c:\1.xml");
try
{
xmlReader.MoveToContent(); // Get beyond the DTD which we don't care
about
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message); // handle undefined DTD
}
try
{
while (xmlReader.Read())
{
symbolNumber++;
if (symbolNumber % 100000 == 0)
Console.WriteLine(symbolNumber);
switch (xmlReader.NodeType)
{
case XmlNodeType.Element:
// Console.Write("<{0}>", xmlReader.Name);
bool bDoAdd = true;
foreach (String memberofArrayList in arrayList)
if (memberofArrayList.Equals(xmlReader.Name))
{
bDoAdd = false;
break;
}
if (bDoAdd)
arrayList.Add(xmlReader.Name);
break;
case XmlNodeType.Text:
// Console.Write(xmlReader.Value);
break;
case XmlNodeType.CDATA:
// Console.Write("<![CDATA[{0}]]>", xmlReader.Value);
break;
case XmlNodeType.ProcessingInstruction:
// Console.Write("<?{0} {1}?>", xmlReader.Name, xmlReader.Value);
break;
case XmlNodeType.Comment:
// Console.Write("<!--{0}-->", xmlReader.Value);
break;
case XmlNodeType.XmlDeclaration:
// Console.Write("<?xml version='1.0'?>");
break;
case XmlNodeType.Document:
break;
case XmlNodeType.DocumentType:
// Console.Write("<!DOCTYPE {0} [{1}]", xmlReader.Name, xmlReader.Value);
break;
case XmlNodeType.EntityReference:
// Console.Write(xmlReader.Name);
break;
case XmlNodeType.EndElement:
// Console.Write("</{0}>", xmlReader.Name);
break;
}
}

xmlReader.Close();
foreach (String memberofArrayList in arrayList)
Console.WriteLine(memberofArrayList);
Console.WriteLine("This program has terminated.");
}
catch(Exception e)
{
xmlReader.Close();
Console.WriteLine("Exception: " + e.Message);
Console.WriteLine(e.StackTrace);
Console.WriteLine(e.Source);
foreach (String memberofArrayList in arrayList)
Console.WriteLine(memberofArrayList);
Console.WriteLine("This program has terminated.");
return;
}

}
}
}
 
I did as you suggested and obtained the following in a message box:

A first chance exception of type 'System.IndexOutOfRangeException' occurred in system.xml.dll

Additional information: Index was outside the bounds of the array.

The program was halted at some point inside the runtime library. My code had called into the runtime library at the while statement.

The debugger didn't show code inside the runtime library. The array bounds error occurred outside my purview. Is this an issue?
 
The program source code has already been posted in this thread. The data source is 11 gigabytes of XML. XML being wordy, that compresses down to fewer than 600 megabytes using PKZIP. I would be happy to put it on a CD and mail it.
 
Back
Top