471,321 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

DOM Questions

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(xmlFile)
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim xDoc = Settings.Products
Dim xNodeList As XmlNodeList
Dim xNode As XmlNode

xNodeList = xDoc.SelectNodes("/products/product/id")

For Each xNode In xNodeList

cmbProducts.Items.Add(xNode.InnerText)
Next

'While xmlTr.Read
' If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Element Then
' cmbProducts.Items.Add(xmlTr.ReadString)
' End If
'End While
'xmlTr.Close()

'xmlDoc = New XmlDocument
'xmlDoc.Load(xmlFile)

End Sub

I am getting this error
An unhandled exception of type 'System.NullReferenceException' occurred in
microsoft.visualbasic.dll

Additional information: Object variable or With block variable not set.

The line in question is
xNodeList = xDoc.SelectNodes("/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>Carwell</company>
<address>Street Address</address>
<city>City</city>
<state>State</state>
<zip>Zip</zip>
</product>

<!-- Next product here-->
</products>

Any ideas?
Jul 21 '05 #1
0 831

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by softwareengineer2006 | last post: by
reply views Thread by connectrajesh | last post: by
8 posts views Thread by Krypto | last post: by
reply views Thread by ramu | last post: by
1 post views Thread by ramu | last post: by
reply views Thread by ramu | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.