CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
parsing xml

 



ticketE
Novice

Apr 20, 2013, 3:29 PM

Post #1 of 2 (643 views)
parsing xml Can't Post

Hi, I have to do a script that make a parse of an xml file.
Particulary this script have to save every word conteined in block "category" or "content:encoding" for create a page of feed. Obviously without consider CDATA block.

I searched for a long time how to use the XML::Parse but I didn't understand.
How could I access to this words?
I have to use the SAX library.
Please help me


Code
#!/usr/bin/perl -w 

use strict;
use warnings;
use utf8;
use XML::Parser;
use LWP::Simple;

my $ruta;

$ruta = "http://www.elpais.com/rss/feed.html";
my $re = get($ruta);

my $nuevofichero;
$nuevofichero='file.xml';
open(NEWFILE, ">>$nuevofichero") || die("impossible to open file : $nuevofichero");

print NEWFILE $re;
my $p;

$p = new XML::Parser(Style=>'Subs',
Pkg=>'Este');
$p->parse($re);
exit;
package Este;
my $message;
sub category{
my ($pkg,$element,%attr) = @_;
#what does this line? I only saw that element or message contains "category"
$message = \%attr;
print $element;
}
sub _category{ #for tag </category>

}



BillKSmith
Veteran

Apr 23, 2013, 12:01 PM

Post #2 of 2 (619 views)
Re: [ticketE] parsing xml [In reply to] Can't Post

Refer to CPAN for SAX parsing modules. I believe that this is what you mean by 'SAX library'.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives