Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Strange behaviour when parsing a XML file

Reply
Thread Tools

Strange behaviour when parsing a XML file

 
 
Francesco Moi
Guest
Posts: n/a
 
      07-26-2005
Hi.

I want to parse these XML contents:
http://news.search.yahoo.com/news/rss?va=linux (This is a RSS file)

I tried with:
----------------
use LWP::Simple qw($ua get);
use LWP::Simple qw($ua head);

use HTML::TokeParser;

use LWP::UserAgent;

my $Url = "http://news.search.yahoo.com/news/rss?va=linux";
my $content = get($Url);

$parser=HTML::TokeParser->new(\$content);

while (my $token = $parser->get_token) {

my $tag_type = shift @{ $token };

if ($tag_type eq 'S') {

my($tag, $attr, $attrseq, $rawtxt) = @{ $token };

if ($tag eq 'title'){$title =
$parser->get_trimmed_text("/title");}
if ($tag eq 'link'){$link = $parser->get_trimmed_text("/link");}
if ($tag eq 'description'){
$description = $parser->get_trimmed_text("/description");
print "$title - $link - $description\n\n";}}}
------------

But I get this information:
---------
<![CDATA[Foo_Title]]> - Foo_Url -
--------

"<![CDATA" appears (no idea about its meaning) and no data about
description.

However if I substitute
"http://news.search.yahoo.com/news/rss?va=linux" with
"http://www.boingboing.net/index.rdf", it works OK.

Whay am I doing wrong? Regards.

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-26-2005
Francesco Moi <> wrote:

> "<![CDATA" appears (no idea about its meaning)



http://www.google.com/search?hl=en&q...marked+section


> Whay am I doing wrong?



Nothing that I can see.

Did you want the code to do something different from what it is doing?


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
Francesco Moi
Guest
Posts: n/a
 
      07-27-2005
Hi Tad.

Yes, I would like to get 'Foo_Title' instead of '
<![CDATA[Foo_Title]]>', and 'Foo_Description' instead of nothing.

Regards.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
Parsing XML input from web form into namespaced xml file Jason XML 2 04-28-2007 12:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
[XML::XSLT] empty result while parsing xml file PL Perl Misc 2 12-14-2004 10:24 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57