Greetings fellow monks! In an earlier thread a monk recommended that I try out XML::Twig for parsing an Atom feed, and for the most part, it works out great. The code I have so far:
my $content = get("foo/bar.xml"); die "Couldn't get it!" unless defined $content; my $t= XML::Twig->new( # the twig will include just the root and selected titles twig_roots => { 'summary/div' => \&grabDiv, 'title' => \&grabTitle, 'entry/link' => \&grabLinks + } ); $t->parse($content); sub grabDiv { my( $t, $elt)= @_; push ( @divs , $elt->text); # print the text (including sub-e +lement texts) $t->purge; # frees the memory } sub grabTitle { my( $t, $elt)= @_; push( @headlines, $elt->text); # print the text (including su +b-element texts) $t->purge; # frees the memory } sub grabLinks { my( $t, $elt)= @_; my $thingey = $elt->{'href'}; push( @links, $elt->text); # print the text (including sub-el +ement texts) $t->purge; # frees the memory }
This works great, except for the fact that the links in an atom feed are stored like this:
<link href="foo/bar.html" rel="alternate" title="Foo" type="text/html" +/>
Ive sat here furiosly staring at the screen for some time now, but I cant seem to find the answer. Is there a way XML::Twig can do this or will I have to come up with some kind of dirty regex?

In reply to Parsing XML that contains HTML by ruhk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.