reyjrar has asked for the wisdom of the Perl Monks concerning the following question:
syntax error at line 1, column 0, byte 0 at /usr/lib/perl5/vendor_perl +/5.6.1/i386-linux/XML/Parser.pm line 185
#!/usr/bin/perl use strict; use warnings; use XML::Parser; use LWP::Simple; our %XLINK; my $parser = new XML::Parser( Handlers => { Start => \&handle_start, End => \&handle_end } ); $parser->parse('test.xml'); sub handle_start { my $expat = shift; my $element = shift; my %attrs = @_; foreach my $attr (keys %attrs) { my ($ns,$elm) = split /\:/, $attr, 2; next unless $ns =~ /xmlns/i; if($attrs{$attr} eq 'http://www.w3.org/1999/xlink') { $XLINK{label} = $elm; $XLINK{element} = $element; last; } } my %link = (); if($XLINK{label}) { foreach my $attr (grep /$XLINK{label}/, keys %attrs) { my ($ns,$a) = split /\:/,$attr,2; next unless $ns eq $XLINK{label}; $link{lc $a} = $attrs{$a}; } if(exists $link{href} && $link{type} eq 'simple') { print retrieve($link{href}); } } } sub handle_end { my $expat = shift; my $element = shift; %XLINK = () if $element eq $XLINK{element}; } sub retrieve { my $url = shift; return get($url); }
<?xml version='1.0'?> <test> <remote xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:title="testing this thing" xlink:href="http://divisionbyzero.net/~brad/xml/test.xml"> Testing this thing </remote> <local> <cat name="chunky"> <kitten>funky</kitten> <kitten>monkey</kitten> </cat> </local> </test>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Parser question.
by mirod (Canon) on Nov 04, 2002 at 19:06 UTC | |
|
Re: XML::Parser question.
by seattlejohn (Deacon) on Nov 04, 2002 at 19:07 UTC | |
|
Re: XML::Parser question.
by FamousLongAgo (Friar) on Nov 04, 2002 at 19:07 UTC | |
|
Re: XML::Parser question.
by mirod (Canon) on Nov 04, 2002 at 19:32 UTC | |
by reyjrar (Hermit) on Nov 04, 2002 at 19:36 UTC | |
|
Re: XML::Parser question.
by Arrowhead (Monk) on Nov 04, 2002 at 19:07 UTC |