I have been working with xml, and svn *codebase* for 2 projects now, but never really used url's for picking up xml files.
Now I found this script, that doesn't work:
[perl]#!/usr/bin/perl -w
use strict;
use CGI;
use XML::Simple;
my $xml = new XML::Simple;
my $xmlData = $xml->XMLin("someurl");
print "$xmlData->{code} name is $xmlData->{name} countryname is $xmlData->{CountryName} section\n";[/perl]
So basically I want to retreive a xml document from a url, and then write it away later, so right now all I need is to have a variable, which can show me the elements of the xml file.
hope you can help me.
greetings.
[perl]#!/usr/bin/perl -w
use strict;
use CGI;
use LWP::Simple;
use XML::TreeBuilder;
my $url = "http://maps.google.com/maps/geo?q=";
my $google_code = "ABQIAAAAdyFdLejQuxLR-DS7Xwf_ghTToTrERikbexcU9K8fttM4HbfNkBTdvrL8Yjz6FdJPefFm8jXo852aDA";
for(my $pc=11114; $pc < 11115; $pc++){
for(my $pl=80; $pl < 82; $pl++){
for(my $pl1=80; $pl1 < 82; $pl1++){
print retreiveXml(dirtyNumberTrick($pc) . chr($pl) . chr($pl1), $url, $google_code) . "\n";
}
}
}
sub dirtyNumberTrick{
my($value) = @_;
return substr($value,1);
}
sub retreiveXml{
my($pc, $url, $google_code) = @_;
my $link = "$url$pc,NL&output=xml&key=$google_code";
my $xmlPage = get $link;
extractDataXml("$xmlPage");
}
sub extractDataXml{
my ($dataToUse) = @_;
my $tree = XML::TreeBuilder->new();
$tree->parse($dataToUse);
print $dataToUse;
foreach my $postalCodeData ($tree->find_by_tag_name('Response')){
my $blie = $postalCodeData->find_by_tag_name('name');
print $blie;
}
}
[/perl]
This is supposed to show the <name>1032,ER</name>
error comes up,
not well-formed (invalid token) at line 9, column 25, byte 243 at C:/Perl/lib/XML/Parser.pm line 187
heeelp please, this is annoying the crap out of me :p
I generally use regular expressions to parse XML. A one line regular expression is usually all you need to parse a given feed, which is vastly more efficient and gets around picky parser issues.
[edit: typo]
[edited by: IanKelley at 9:03 pm (utc) on Nov. 11, 2008]