carterniall has asked for the wisdom of the Perl Monks concerning the following question:
I am aware that this is an undefined KML as ultimatly I want to parse the KML but am keeping it simple for the moment. The PERL script I am using is:<?xml version='1.0' encoding='UTF-8'?> <Document> <open>0</open> <name>Gazetteer for Scotland: Settlements</name> <Placemark> <name><![CDATA[ Abbey Strand ]]></name> <description><![CDATA[ The Abbey Strand is a short street, lying immediately outside the +Palace of Holyroodhouse, which represents the very last section of Ed +inburgh's Royal Mile. It represented the extent of the precincts of H +olyrood Abbey (the ruins of which stand next to the palace) and hence + the boundary of 'sanctuary', which is still marked by brass studs an +d the letter 'S' in the road. <p><a href="http://getamap.ordnancesurvey.co.uk/getamap/frames.htm?map +Action=zoomabs&mapX=326775&mapY=673975&zoomLevel=6&isGeo=y">SHOW OS M +AP</a>, ]]></description> <LookAt> <longitude>-3.17423</longitude> <latitude>55.95277</latitude> <range>2000</range> <tilt>75</tilt> <heading>0</heading> </LookAt> <Point> <coordinates>-3.17423,55.95277,0</coordinates> </Point> </Placemark> <Placemark> <name><![CDATA[ Abbeyhill ]]></name> <description><![CDATA[ A small district of Edinburgh, is centred to the south of London R +oad, a half-mile (1 km) east of Princes Street, Abbeyhill lies on a r +idge that runs east from Calton Hill to Meadowbank. The district take +s its name from Holyrood Abbey, indeed there is also a road called Ab +beyhill leading from the Abbey which lies a ruin next to the Palace o +f Holyroodhouse. <p><a href="http://getamap.ordnancesurvey.co.uk/geta +map/frames.htm?mapAction=zoomabs&mapX=327000&mapY=674400&zoomLevel=6& +isGeo=y">SHOW OS MAP</a>, ]]></description> <LookAt> <longitude>-3.17075</longitude> <latitude>55.95705</latitude> <range>2000</range> <tilt>75</tilt> <heading>0</heading> </LookAt> <Point> <coordinates>-3.17075,55.95705,0</coordinates> </Point> </Placemark> <Placemark> <name><![CDATA[ Abbeymount ]]></name> <description><![CDATA[ From back of Place Names of Edinburgh Book (can identify district +by streets it references!) <p><a href="http://getamap.ordnancesurvey.co.uk/getamap/frames.htm?map +Action=zoomabs&mapX=326900&mapY=674200&zoomLevel=6&isGeo=y">SHOW OS M +AP</a>, ]]></description> <LookAt> <longitude>-3.1723</longitude> <latitude>55.95524</latitude> <range>2000</range> <tilt>75</tilt> <heading>0</heading> </LookAt> <Point> <coordinates>-3.1723,55.95524,0</coordinates> </Point> </Placemark> </Document>
I think it is because the above gives a hashref (?) instead of an array but I have no idea how then to parse out what I want! Please help! Niall#!/usr/bin/perl # Script to illustrate how to parse a simple XML file # and dump its contents in a Perl hash record. use XML::Simple; use XML::Parser; use LWP::Simple; use Data::Dumper; my $url= "http://xweb.geos.ed.ac.uk/~s0341330/module3/test.xml"; my $xml = get ($url) or die "I can't get the feed you want"; my $parser = XML::Simple->new( ); my $Document = $parser->XMLin("$xml"); foreach my $Placemark (@{$Document->{Placemark}}) { my $var = $Placemark->{name} . "\n"; print "$var"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Simple troubles
by moritz (Cardinal) on May 23, 2008 at 12:09 UTC | |
by Anonymous Monk on May 26, 2008 at 08:06 UTC | |
by moritz (Cardinal) on May 26, 2008 at 08:22 UTC | |
by carterniall (Novice) on May 27, 2008 at 08:18 UTC | |
by moritz (Cardinal) on May 27, 2008 at 09:13 UTC | |
by carterniall (Novice) on May 26, 2008 at 12:17 UTC | |
by moritz (Cardinal) on May 26, 2008 at 12:29 UTC | |
|