Strange behaviour when parsing a XML file

Discussion in 'Perl Misc' started by Francesco Moi, Jul 26, 2005.

  1. 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.
     
    Francesco Moi, Jul 26, 2005
    #1
    1. Advertising

  2. Francesco Moi <> wrote:

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



    http://www.google.com/search?hl=en&q=HTML "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
     
    Tad McClellan, Jul 26, 2005
    #2
    1. Advertising

  3. Hi Tad.

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

    Regards.
     
    Francesco Moi, Jul 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    748
  2. Replies:
    38
    Views:
    878
    Eric Sosman
    Nov 16, 2011
  3. John Levine
    Replies:
    0
    Views:
    767
    John Levine
    Feb 2, 2012
  4. Erik Wasser
    Replies:
    5
    Views:
    530
    Peter J. Holzer
    Mar 5, 2006
  5. felix
    Replies:
    34
    Views:
    800
    James Kuyper
    Nov 19, 2012
Loading...

Share This Page