Adding XML processing to the websites
Although I’ve been running database driven websites for a couple of years now what I’ve not done before is to access other peoples’ sites from my own until now.
A common way to offer people access to corporate databases via the Internet is by way of providing an XML feed. What’s XML? Well, it’s a way of holding offering both the data and the data structures via a webpage. It looks a little bit like normal HTML in that it uses the <angle> brackets but other than that it’s completely different.
The problem is that it’s a very general purpose format and not tied to any particular language. In my case, the site that I wanted to access provided examples in ASP but I use PHP so they weren’t a whole lot of use to me. Neither as it turns out was the big book on XML that I’d bought to get me on the road with the development.
However, as always there’s a lot of help around on the Internet if you look in the right places. After a few abortive attempts I found the PHP routine clsParseXML which provides a very simple yet powerful interface to XML data. Essentially what it does is to read the XML file and return it in an array or rather an array of arrays.
The database I wanted to access is essentially one large structured list of place names around the world each of which have a list of diffent accommodation at them. So, first of all I had to read the entry which listed all the regions ie Africa, Asia, Europe, etc., then choose the code for the region I was looking for and run the query again to get the countries in that region, and so on down to counties. Within the lowest level there’s a link to properties in that area requiring a whole new qyery.
Sounds very complicated, doesn’t it? Actually, it’s very simple and the high level queries run to only a few lines of code:
- region_id=get_region_id(“0″,”Europe”);
- region_id=get_region_id(region_id,”France”);
- region_id=get_region_id(region_id,”Languedoc-Roussillon”);
- region_id=get_region_id(region_id,”Pyrenees Orientale”);
Which gets me a region_id for the properties in the Pyrenees Orientale. With that I call another routine to scan through the properties in that region and return an array containing all the information of properties there.
With that, I was able to run up the HTML to integrate the properties on the external database with those from my own database thus giving, for example, the Languedoc-Roussillon page where the only way to identify the properties from the external database is by the “VR” prefix to their reference numbers.
How long to complete? Well, I started yesterday afternoon and had the test version running in a couple of hours with the live version completed in under an hour this morning. However, in reality it took much less than that as a lot of the time went in looking for that critical routine to read XML into a PHP array.
The game plan was to roll out this development to my sites listing properties around Europe but unfortunately the external database isn’t structured in the same way as my own outside France so I’ll need to run up some code to translate between the two structures first.
Copyright © 2004-2014 by Foreign Perspectives. All rights reserved.