P
Paulers
Hello all,
I am trying to parse an XML document and populate objects to store in
an ArrayList but I am having issues when an element is NULL. I cant
seem to figure out how to handle it. I keep getting a null pointer
exception if a 'name' element is missing from the xml. Here is my code.
Any help is greatly appreciated.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim menuFile As String = Application.StartupPath & "\" &
"vars.xml"
Dim doc As XmlDocument = New XmlDocument()
doc.Load(menuFile)
Dim myVars As XmlNodeList =
doc.DocumentElement.SelectNodes("/Root/Row")
Console.WriteLine(myVars.Count)
Dim element As XmlElement
For Each element In myVars
Dim type = element.ChildNodes.Item(0).InnerText
Dim variable = element.ChildNodes.Item(1).InnerText
Dim startByte = element.ChildNodes.Item(2).InnerText
Dim endByte = element.ChildNodes.Item(3).InnerText
Dim totalBytes = element.ChildNodes.Item(4).InnerText
Dim name = element.ChildNodes.Item(5).InnerText
Next
End Sub
I am trying to parse an XML document and populate objects to store in
an ArrayList but I am having issues when an element is NULL. I cant
seem to figure out how to handle it. I keep getting a null pointer
exception if a 'name' element is missing from the xml. Here is my code.
Any help is greatly appreciated.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim menuFile As String = Application.StartupPath & "\" &
"vars.xml"
Dim doc As XmlDocument = New XmlDocument()
doc.Load(menuFile)
Dim myVars As XmlNodeList =
doc.DocumentElement.SelectNodes("/Root/Row")
Console.WriteLine(myVars.Count)
Dim element As XmlElement
For Each element In myVars
Dim type = element.ChildNodes.Item(0).InnerText
Dim variable = element.ChildNodes.Item(1).InnerText
Dim startByte = element.ChildNodes.Item(2).InnerText
Dim endByte = element.ChildNodes.Item(3).InnerText
Dim totalBytes = element.ChildNodes.Item(4).InnerText
Dim name = element.ChildNodes.Item(5).InnerText
Next
End Sub