VB.NET looping through XML to store in singleton
Posted
by rockinthesixstring
on Stack Overflow
See other posts from Stack Overflow
or by rockinthesixstring
Published on 2010-05-01T19:07:20Z
Indexed on
2010/05/01
20:47 UTC
Read the original article
Hit count: 251
I'm having a problem with looping through an XML file and storing the value in a singleton
My XML looks like this
<values>
<value></value>
<value>$1</value>
<value>$5,000</value>
<value>$10,000</value>
<value>$15,000</value>
<value>$25,000</value>
<value>$50,000</value>
<value>$75,000</value>
<value>$100,000</value>
<value>$250,000</value>
<value>$500,000</value>
<value>$750,000</value>
<value>$1,000,000</value>
<value>$1,250,000</value>
<value>$1,500,000</value>
<value>$1,750,000</value>
<value>$2,000,000</value>
<value>$2,500,000</value>
<value>$3,000,000</value>
<value>$4,000,000</value>
<value>$5,000,000</value>
<value>$7,500,000</value>
<value>$10,000,000</value>
<value>$15,000,000</value>
<value>$25,000,000</value>
<value>$50,000,000</value>
<value>$100,000,000</value>
<value>$100,000,000+</value>
</values>
And my function looks like this
Public Class LoadValues
Private Shared SearchValuesInstance As List(Of SearchValues) = Nothing
Public Shared ReadOnly Property LoadSearchValues As List(Of SearchValues)
Get
Dim sv As New List(Of SearchValues)
If SearchValuesInstance Is Nothing Then
Dim objDoc As XmlDocument = New XmlDataDocument
Dim objRdr As XmlTextReader = New XmlTextReader(HttpContext.Current.Server.MapPath("~/App_Data/Search-Values.xml"))
objRdr.Read()
objDoc.Load(objRdr)
Dim root As XmlElement = objDoc.DocumentElement
Dim itemNodes As XmlNodeList = root.SelectNodes("/values")
For Each n As XmlNode In itemNodes
sv.Add(New SearchValues(n("@value").InnerText, n("@value").InnerText))
Next
SearchValuesInstance = sv
Else : sv = SearchValuesInstance
End If
Return sv
End Get
End Property
End Class
My problem is that I'm getting an object not set to an instance of an object
on the sv.Add(New SearchValues(n("@value").InnerText, n("@value").InnerText))
line.
© Stack Overflow or respective owner