Skip to main content Skip to secondary content

Do you need world data in XML format?

No comments

A client of mine, a travel agency, required a sort of country profile for each country in the world. One requirement for this section was that a map be displayed of the country with the country’s capital highlighted.

After gathering more requirements I knew Google Maps API was the answer. Before I began coding I started looking for some world country meta-data, anything I could find.

I did find a few helpful things. Keep in mind that what I needed was:

  • Country Codes (Each country has a unique identifier)
  • Flags
  • Capitals
  • Lat and long of each capital

I whole heartedly (and very ignorantly I came to find) expected to find someone who had created an XML file that contained all of this as I was sure (and still am) that someone has crossed this problem before. I did not find any place, person, or file that solved this for me. If you do find something somewhere I would love for you to post a link in a comment or email me to share with all.

What I did find was the following.

Country Codes

I was looking for 2 letter country codes (which I’ll explain why later). By wikipedia-ing “country codes” I found this page which thoroughly describes the 2 letter country code system and defines for each country. This alone was useful but I was disappointed that this was not downloadable. However, if you go all the way to the bottom you can download the 2 letter codes file in text format or in xml format (zip file). This was but one piece of the puzzle.

Flags

I cheated a bit, I purposely searched for 2 digit country codes because I already knew that Famfamfam’s Mark James had already developed country flag icons, named by the 2 letter country code so that’s why I made finding the 2 digit code a priority. This allowed me, and you too, to simply call countrycode+src and immediately have my country’s flag loaded.

Capitals

Up to this point I had saved myself alot of time from the two prior contributions. Capitals weren’t as easy. I had to piecemeal a file together using this webpage provided by wikipedia. It was a vigorously ugly find and replace job, but I finally got the file whittled down to bare bones.

Lat and Long of Each Capital

I actually used a fairly nice free service I found where you could upload a file that contained the cities and countries you wanted and it would return with a lat and long for each location. 95% of the points were accurate, so I really enjoyed it. Unfortunately, I cannot find this service again. For the remaining places I used the Lat and Long Itouch Map, which has been updated extensively since my last use. When I used it it was simply a google map which allowed you to zoom and pan then when you clicked on a location it would display a balloon that held the lat and long.

Mashing

I spent about an hour mashing and find/replacing until I got what I wanted.

My Final Product

I have posted my process to help anyone who is searching for a similar solution. You may not find my final file useful but another site I link to. My hope is to eliminate the 4/5 hours I spent total surveying and compiling this information. My final file works perfectly for what I needed. I even included a desc attribute so I could include a description if my client desired so. While I am not willing to divulge my JavaScript code, I am willing to give my XML file to the public. But seriously, if you know this is what you need, you should have the skill to write the JavaScript in 30 min or less to apply this file to a Google Map.

country-meta-data.zip

If you use this file or find this post useful in general send me a note, that’s all. Hope it saves someone some time.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Articles

Recent Comments

Teach Me the Web Relaunch

  • Mike Ames - October 25, 2008 12:04 pm I am still doing web projects on my own but our school does...
  • Jeff - October 24, 2008 6:15 am Mike, good to hear from you. I use Expression Engine to manage...
  • Mike Ames - October 23, 2008 8:22 pm Alright Boss, I got a few questions / Comments 1st. I hear...

I’m Married

  • Stefan Vervoort - June 4, 2008 2:43 pm Congrats, happy marriage!
  • Jeff - March 3, 2008 4:19 pm Much appreciated. Look at you with your shameless plug for your new...

We’ve Changed Our Name

  • leveille - May 22, 2008 3:29 pm hmmmm. I wonder what prompted this change.

Why iGoogle has changed my life

  • Mike Ames - May 8, 2008 9:33 pm I love i-Google for a few reasons some of which were mentioned....

What’s Popular?

  • Zac Gordon - March 17, 2008 7:32 pm I hear that! http://del.icio.us/zacgordon/w ebdesign Be...