From 15737de254d83620724a104da0924c88d8c6fdbd Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 16 Aug 2014 23:48:04 +0200 Subject: [PATCH] Redesign geodata.xml so it also stores country names --- data/geonames/geonames_process.pl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/data/geonames/geonames_process.pl b/data/geonames/geonames_process.pl index 5311276..e8bddeb 100644 --- a/data/geonames/geonames_process.pl +++ b/data/geonames/geonames_process.pl @@ -16,25 +16,34 @@ while () { } close(TIMEZONES); +my $xml_file = IO::File->new('>geodata.xml'); +my $writer = XML::Writer->new(OUTPUT => $xml_file, NEWLINES => 0); + +$writer->xmlDecl('utf-8'); +$writer->startTag('geodata'); +$writer->startTag('countries'); + open(COUNTRIES, 'countryInfo.txt') or die("Cannot open countryInfo.txt: $!\n"); while () { my ($country_code, $iso3, $iso_numeric, $fips, $name, $capital, $area, $population, $continent, $tld, $currency_code, $currency_name, $phone, $postal_code_format, $postal_code_regex, $languages, $geonameid, $neighbours, $equivalent_fips_code) = split(/\t/, $_); next if ($country_code !~ /^[A-Z]{2}$/); + $writer->emptyTag('c', + 'n' => $name, + 'c' => $country_code, + ); + if ($country_code =~ /^[A-Z]{2}$/) { $countries{$country_code} = $name; } } close(COUNTRIES); +$writer->endTag('countries'); +$writer->startTag('places'); + open(GEONAMES, "cities.txt") or die("Cannot open cities.txt: $!\n"); -my $xml_file = IO::File->new('>geodata.xml'); -my $writer = XML::Writer->new(OUTPUT => $xml_file, NEWLINES => 0); - -$writer->xmlDecl('utf-8'); -$writer->startTag('geodata'); - while () { chomp($_); my ($country_code, $name, $latitude, $longitude, $elevation, $timezone) = split(/\t/, $_); @@ -62,6 +71,7 @@ while () { print $., "\n" if ($. % 19083 == 0); } +$writer->endTag('places'); $writer->endTag('geodata'); $writer->end(); $xml_file->close();