"Brent Clark" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi
>
> I have been trying to get my perl to work with an xml doc (about 2 hours
> new to xml).
> I basically just want all the <title>elements
>
> would anyone be so kind as too share a link of doc etc as how I can
> takle this.
>
> Kind Regards and thanks in advance
> Brent Clark
>
> =====================================================
> my $file = get("http://currencysource.com/RSS/ZAR.xml";);
>
> foreach my $element ($file){
> if ($element =~ /title/i){
> print "$element<BR>";
> }
> }

Piece of cake whith XML::XPath:

[EMAIL PROTECTED] misc]$ cat parserss.pl
use warnings;
use strict;

use LWP::Simple;
use XML::XPath;

my $url = 'http://currencysource.com/RSS/ZAR.xml';
my $xml = LWP::Simple::get( $url );

my $xp  = XML::XPath->new( xml => $xml );

my $nodeset = $xp->find( '/rss/channel/item' );
foreach my $node ( $nodeset->get_nodelist ) {
  print $xp->findvalue( './title', $node ), "\n";
}
[EMAIL PROTECTED] misc]$ perl parserss.pl
1 ZAR = AED (0.649063)
1 ZAR = ARS (0.523159)
1 ZAR = AUD (0.226934)
1 ZAR = BHD (0.066453)
...

How cool is that?

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to