I have a class that holds my XML data.
Public Class Settings
Private Shared xmlDoc As XmlDocument
Public Shared Property Products() As XmlDocument
Get
If xmlDoc Is Nothing Then
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument
xmlDoc = New XmlDocument
xmlDoc.Load(xml File)
End If
Return xmlDoc
End Get
Set(ByVal Value As XmlDocument)
xmlDoc = Value 'no real need to validate
End Set
End Property
End Class
I am trying to load this into a combobox. Here is my code (the commented out
is what I did before..)
Private Sub Zadig_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim xDoc = Settings.Produc ts
Dim xNodeList As XmlNodeList
Dim xNode As XmlNode
xNodeList = xDoc.SelectNode s("/products/product/id")
For Each xNode In xNodeList
cmbProducts.Ite ms.Add(xNode.In nerText)
Next
'While xmlTr.Read
' If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Ele ment Then
' cmbProducts.Ite ms.Add(xmlTr.Re adString)
' End If
'End While
'xmlTr.Close()
'xmlDoc = New XmlDocument
'xmlDoc.Load(xm lFile)
End Sub
I am getting this error
An unhandled exception of type 'System.NullRef erenceException ' occurred in
microsoft.visua lbasic.dll
Additional information: Object variable or With block variable not set.
The line in question is
xNodeList = xDoc.SelectNode s("/products/product/id")
Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>
<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwel l</company>
<address>Stre et Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>
<!-- Next product here-->
</products>
Any ideas?
Public Class Settings
Private Shared xmlDoc As XmlDocument
Public Shared Property Products() As XmlDocument
Get
If xmlDoc Is Nothing Then
Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument
xmlDoc = New XmlDocument
xmlDoc.Load(xml File)
End If
Return xmlDoc
End Get
Set(ByVal Value As XmlDocument)
xmlDoc = Value 'no real need to validate
End Set
End Property
End Class
I am trying to load this into a combobox. Here is my code (the commented out
is what I did before..)
Private Sub Zadig_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim xDoc = Settings.Produc ts
Dim xNodeList As XmlNodeList
Dim xNode As XmlNode
xNodeList = xDoc.SelectNode s("/products/product/id")
For Each xNode In xNodeList
cmbProducts.Ite ms.Add(xNode.In nerText)
Next
'While xmlTr.Read
' If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Ele ment Then
' cmbProducts.Ite ms.Add(xmlTr.Re adString)
' End If
'End While
'xmlTr.Close()
'xmlDoc = New XmlDocument
'xmlDoc.Load(xm lFile)
End Sub
I am getting this error
An unhandled exception of type 'System.NullRef erenceException ' occurred in
microsoft.visua lbasic.dll
Additional information: Object variable or With block variable not set.
The line in question is
xNodeList = xDoc.SelectNode s("/products/product/id")
Here is my XML file
<?xml version="1.0" encoding="utf-8" ?>
<products>
<!-- Repeat the structure below for each product. -->
<product>
<id>CP-90, T-32</id>
<company>Carwel l</company>
<address>Stre et Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>
<!-- Next product here-->
</products>
Any ideas?