Question

What I have been trying to do, is to use a XML file to access a array of data that I wish to have stored on the web. The file looks like this:

<resources>
    <60020> 13.5 </60020>
    <50020> 11.2 </50020>
</resources>

The program grabs the user's GPS coordinates and then geocodes them to a zip code, that part I have down. What I wished to do after that, was to compare that zip code to the zip codes in the XML file and then return a integer based on the closest zip code. For instance, if the user has zip code 60013, then the program would see that 60020 is the closest zip code, and then return 13.5 based on that search.

I have already tried making a SAXParser, and I can return the first value, however, I cannot how to force the SAXParser to read through the whole document to find the nearest value. I also already have a algorithm to find the nearest value (simple for loop checking for difference in values), but again, I am stuck on the whole idea of how to check the whole list of values. Am I using the wrong type of storage method? Should I be using SQL? Or a different parser?

Thanks for your help.

Was it helpful?

Solution

I better idea would be to round off the zip code first and then search it in the XML file. I would recommend Xpath Api for querying the XML file. I very good tutorial about Xpath can be found here

http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html

and as SAXparser itself will look for tags, it won't roundoff them, allover XPath is more prefered for searching XML documents, as it is relatively easy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top