The forum helped me to get my XMLReader to work a while back but I just now noticed a problem. This is how I am handling the xml in my XMLReader…
?xml version="1.0" encoding="UTF-8"?>
<schools>
<details>
<name>Academy of the Pacific</name>
<id>1</id>
<districtid>1</districtid>
<rank>0</rank>
</details>
<details>
<name>Ahuimanu Elementary</name>
<id>107</id>
<districtid>6</districtid>
<rank>0</rank>
</details>
</schools>
The goal here was to put each school in a dictionary and then put them all into a single dictionary. To do this I created the follwoing properties in my XMLReader
Output
DetailsDictionary
Key
TypeKey
DetailsKey
I call the reader like this…
Dim reader As New myXMLReader
reader.Output = session.Schools //a dictionary
reader.TypeKey = "schools"
reader.DetailsKey = "details"
reader.Parse(data)
Then my event handlers handle the stream like this…
//StartElement
Key = name
If Key = DetailsKey Then
Dim d As New Dictionary
detailsDictionary = d
End If
//Characters
If Key <> TypeKey And Key <> DetailsKey Then
detailsDictionary.Value(key)=detailsDictionary.Lookup(key,"")+s
End If
//EndElement
If name = DetailsKey Then
output.Value(detailsDictionary.Value("id"))= detailsDictionary
End If
I thought was working just fine. I realized this morning, however, that later on in the session I am randomly losing the first dictionary added to the Schools dictionary by the XMLReader.
I think I understand what is happening when I put the a detailsDictionary into the Output dictionary I am actually putting a reference to the memory allocation for detailsDictionary. Somewhere along the way that memory block is getting changed. It is not nil, the dictionary is just empty.
Any ideas? Perhaps my whole approach above is flawed.