Can't read XML data above element(12)

warrent

Member
Joined
Nov 19, 2005
Messages
12
Programming Experience
3-5
I'm trying to read data from an XML file with 18 elements. Elements 0 through 12 work fine, but when I try to read element(13) or above I get this error:
An unhandled exception of type 'System.NullReferenceException' occurred in Test1.exe

Additional information: Object reference not set to an instance of an object.

Has anyone encountered this problem? Microsoft claims to have a hotfix for this error but it only works for certain VB.net applications. I haven't found anything info relating this error to using .XML files.

http://www.vbdotnetforums.com/
 
Private Sub Test1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim AppExe = Application.StartupPath

Dim xmlLoadTest As System.Xml.XmlDocument = New System.Xml.XmlDocument

'Open config.xml file
xmlLoadTest.Load(AppExe & "\config.xml")

'Get the nodes for config.xml file
Dim xmlLoadTestnodelist As System.Xml.XmlNodeList = xmlLoadTest.SelectNodes("/config")

'Load each value into the proper textbox
Dim xmlLoadTestnode As System.Xml.XmlNode
For Each xmlLoadTestnode In xmlLoadTestnodelist
txtBox1.Text = xmlLoadTestnode.ChildNodes.Item(12).InnerText
txtBox2.Text = xmlLoadTestnode.ChildNodes.Item(13).InnerText
Next

End Sub

When you run this code, I always get the error when it tries to read item(13). I've changed (13) to some other numbers. 0 through 12 work fine, but the problem happens when I get to 13 and above. Maybe it's the way I wrote my .xml file, but it's pretty basic. I'm using VB.Net 2003. Maybe there's some kind of Microsoft run errors associated with 2003 version.

Here is my .xml file:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<lt0>0.5</lt0>
<lt1>1</lt1>
<lt2>1.5</lt2>
<lt3>40</lt3>
<lt4>660</lt4>
<lt5>0</lt5>
<lt6>660</lt6>
<lt7>0</lt7>
<lt8>.375</lt8>
<lt9>6</lt9>
<lt10>6</lt10>
<lt11>True</lt11>
<lt12>True</lt12>
<lt13>2000</lt13>
<lt14>10000</lt14>
<lt15>1000</lt15>
<lt16>5000</lt16>
<lt17>1000</lt17>
<lt18>500</lt18>
</config>
 
Sorry guys. Looks like the problem fixed itself. I'm able to read the data now. Not sure what was wrong before. Didn't make any changes to the program. It just started working like normal.

Appreciate the help.

Note: If the problem isn't making any sense, reset your computer and try again.
 
Back
Top