I'm able to process WordPress' inexcusably messy output using HTML::TreeBuilder::XPath. However when I try to call the delete method on the object I get warnings or errors. I would like the problem to go away but neither have access to the site producing the document nor to WordPress upstream which is actually where the fault lies. Anyway, when I call delete after otherwise successful processing of the document I get the following error:

Deep recursion on subroutine "HTML::Element::delete" at /usr/share/perl5/HTML/Element.pm line 567. Deep recursion on subroutine "HTML::Element::delete_content" at /usr/share/perl5/HTML/Element.pm line 580.

Can I just use undef instead of calling the delete method? Or is there another approach which is better? I use HTML::TreeBuilder::XPath extensively in the real script but maybe could or should do some pre-processing with a different parser though I'd rather not.

Here is a stripped down example of the problem:

#!/usr/bin/perl use HTML::TreeBuilder::XPath; use strict; use warnings; my $ent = HTML::TreeBuilder::XPath->new; $ent->parse_file(\*DATA); $ent->delete; exit(0); __DATA__ <html> <head> <title>foo bar</title> </head> <body> foo <br /> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <center> <strong>bar</strong> <br /> <center>(baz)</center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </center> </body> </html>

In reply to Unnesting deeply nested HTML elements (Deep recursion on subroutine "HTML::Element::delete") by mldvx4

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.