Hi Everyone! I can't seem to get past this one. I am attempting to use xmlsax to parse the following nominatim.xml file which has the following structure:
What I want to do is parse all the values (lat, lon,<pub>,<road>,<city>,<country>) in each <place> element into an object called "store" and then put each "store" object them into a list. However, xmlsax stops at the <searchresults> in parser_StartElement, not being able to get to the following <place> sub -elements in the .xml file. Can someone see any problems with my code?
This is the xmlsax code:
Update - Sorry, I forgot to include an XML attachment. Hopefully it can be read in by the sax parser.
Thanks!
B4X:
<searchresults>
a="a"
b="b"
<place>
lat="latitude coordinate"
lon="longitude coordinate"
<pub>Awesome Pub </pub>
<house_number>23</house_number>
<road>Victoria Street Lane</road>
<city>Toronto</city>
<country>Canada</country>
</place>
<place>
lat=latitude coordinate
lon=longitude coordinate
<pub>Next Pub </pub>
<house_number>19</house_number>
<road>Dundas Street Lane</road>
<city>Toronto</city>
<country>Canada</country>
</place>
<place>
lat=latitude coordinate
lon=longitude coordinate
<pub>Cool Pub </pub>
<house_number>43</house_number>
<road>Queen Street</road>
<city>Toronto</city>
<country>Canada</country>
</place>
</searchresults>
What I want to do is parse all the values (lat, lon,<pub>,<road>,<city>,<country>) in each <place> element into an object called "store" and then put each "store" object them into a list. However, xmlsax stops at the <searchresults> in parser_StartElement, not being able to get to the following <place> sub -elements in the .xml file. Can someone see any problems with my code?
This is the xmlsax code:
B4X:
Type osmpoint (name As String, house_number As String, road As String, lat As String, _
lon As String)
Dim listofplaces As List
listofplaces.initialize
Sub parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
If Name = "searchresults" Then
Log("Found the searchresults element")
If Name = "place" Then
Log("found the place element")
store.Initialize
store.lat = Attributes.GetValue2("", "lat")
store.lon = Attributes.GetValue2("", "lon")
' listofplaces.Add(store) - don't need it here since I want to store the end elements too
Else
Log("could not find the <place> element in nominatim.xml")
End If
Else
Log("Could not find the <searchresults> element in nominatim.xml")
End If
End Sub
Sub parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If parser.Parents.IndexOf("place") > -1 Then
Select Name
Case "pub"
store.Name = Text.ToString
Log("grabbed the pub name in parser_EndElement")
Case "house_number"
store.house_number = Text.ToString
Log("grabbed the house_number in parser_EndElement")
Case "road"
store.road = Text.ToString
Log("grabbed the road in parser_EndElement")
End Select
End If
If Name = "place" Then
listofplaces.Add(store) 'add the parsed store info to listofplaces
Else
Log("could not find the <place> element in nominatim.xml")
End If
End Sub
Update - Sorry, I forgot to include an XML attachment. Hopefully it can be read in by the sax parser.
Thanks!
Attachments
Last edited: