[Bangalore-pm] Please help me in Parsing KML file in perl using regular expression.(its urgent)

sairam pareek mariassai at gmail.com
Tue Jun 16 03:01:01 PDT 2009


Hi everyone,
Need your help once again

I have a a kml file for parsing (please find the attachment below) I have
used XML::Simple for parsing & for storing the value by hash array(key,
value).

Below is the code::
******************************************************************************************
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

my $file = 'Al waab B villa.kml';

#create a object
my $xm1 = XML::Simple->new();

#read XML file
my $data = $xm1->XMLin("Al waab B villa.kml");

print Dumper($data);

my $tags = $data->{Document}->{Placemark}->{LookAt};
my %hash;
my $val;

foreach $val (keys %$hello) {
push @{$hash{$tags}}, $val;
    }
print Dumper \%hash;

******************************************************************************************

I get output as:


$VAR1 = {
          'HASH(0x1ad903c)' => [
                                 'longitude',
                                 'latitude',
                                 'heading',
                                 'tilt',
                                 'range',
                                 'altitudeMode',
                                 'altitude'
                               ]
        };


For a single key I want tag values between them not the name.

And I want output as::(with a pipe operator between each value)

LookAt =>
51.47891287538003|25.26764114641654|0|3709.372423858944|0-0.002617566196780602|relativeToGround

        wating for your replies.
Thanks in advance.
On Sun, Jun 14, 2009 at 10:57 PM, sairam pareek <mariassai at gmail.com> wrote:

> Thanks for your replies,
>
> I m happy to be in this group, I tried the given solutions, they are
> working fine.
>
> If I have some problem further Ill let you know.
>
> Thanks once again.
>
>
> On Sun, Jun 14, 2009 at 10:02 PM, simran <simran at tlims.cc> wrote:
>
>> probably best to use the XML::Simple module...
>>
>> http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm<http://search.cpan.org/%7Egrantm/XML-Simple-2.18/lib/XML/Simple.pm>
>>
>> 2009/6/15 wolf <superpulse.x at gmail.com>
>>
>> Hey,
>>>
>>> I used your KML file ( renamed it of course ):
>>>
>>> cat test.kml | perl -ne ' print "$1: $2\n " if
>>> m!<(longitude|latitude)\s*?>\s*?([0-9\.]+)\s*?!'
>>>
>>> Hope this helps,
>>>
>>> Cheers,
>>> V
>>>
>>>
>>> 2009/6/14 sairam pareek <mariassai at gmail.com>
>>>
>>>>  Hello everyone.
>>>>
>>>> I have a kml file, and struggling to write a perl script to parse its
>>>> value between tags, this is my first task.
>>>> and the second is to update the value between the tag in the postgresql
>>>> database table. I m attaching the KML file, Please find the attachment. (I
>>>> want to parse the longitude, latitude vlaues in these)
>>>>
>>>>                                                                 Please
>>>> help me, its urgent. Waiting for your replies. Hoping for great help from
>>>> you guys. I wanted to use regular expression for this. I found this group on
>>>> orkut.
>>>>                                       Thanks in advance.
>>>>
>>>> Regards,
>>>> Sairam
>>>>
>>>> --
>>>> "It is not how much you do, but how much love you put in the doing."
>>>>
>>>> _______________________________________________
>>>> Bangalore-pm mailing list
>>>> Bangalore-pm at pm.org
>>>> http://mail.pm.org/mailman/listinfo/bangalore-pm
>>>>
>>>
>>>
>>> _______________________________________________
>>> Bangalore-pm mailing list
>>> Bangalore-pm at pm.org
>>> http://mail.pm.org/mailman/listinfo/bangalore-pm
>>>
>>
>>
>
>
> --
> "It is not how much you do, but how much love you put in the doing."
>



-- 
"It is not how much you do, but how much love you put in the doing."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090616/3dbb171d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Al waab B villa.kml
Type: application/vnd.google-earth.kml+xml
Size: 1498 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090616/3dbb171d/attachment.bin>


More information about the Bangalore-pm mailing list