forked from kaicarver/youbike-stations
/
parsegenxml.pl
53 lines (51 loc) · 1.55 KB
/
parsegenxml.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Produce KML for Google Maps from XML data on the YouBike web site
# The XML data is accessible here:
# http://www.youbike.com.tw/genxml9.php?lat=25.037525&lng=121.56378199999995&radius=5&mode=0
use strict;
use warnings;
use v5.10;
use open ':std', ':encoding(UTF-8)';
use XML::Simple;
use Data::Dumper;
my $xml = new XML::Simple;
my $data = $xml->XMLin('youbike_stations.xml');
my $i = 0;
print <<END;
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Taipei YouBike bicycle-sharing stations</name>
<description><![CDATA[All the stations from the YouBike site.
Their map is a little hard to use. This one makes it possible to get directions on the Google Maps Android app.]]></description>
END
for my $name (sort keys %{$data->{marker}}) {
#say "name: $name";
my $m = {};
$m->{name} = $name;
for my $key (sort keys %{$data->{marker}->{$name}}) {
#say " ", $key, ": ", $data->{marker}->{$name}->{$key};
$m->{$key} = $data->{marker}->{$name}->{$key};
}
my $xmlstr = <<END;
<Placemark>
<name>$m->{name}</name>
<Snippet>$m->{address}</Snippet>
<description><![CDATA[$m->{name}<br>
$m->{address}<br>
$m->{nameen}<br>
$m->{addressen}]]></description>
<Point>
<coordinates>$m->{lng},$m->{lat},0.000000</coordinates>
</Point>
</Placemark>
END
$xmlstr =~ s/Stataion/Sta./g;
$xmlstr =~ s/Sta\.?\(/Sta. (/g;
$xmlstr =~ s/Sta\.Exit (\d)/Sta. (Exit $1)/g;
print $xmlstr;
#last if $i++ > 0;
}
print <<END;
</Document>
</kml>
END