I am trying to modify HTML using TreeBuilder but in the output of as_HTML I am getting some additional tags that are not present in input file. I want input HTML as it is except when I modify it. Current code shows how TreeBuilder is modifying input HTML. Can anyone suggest me any option to avoid input HTML modification except when explicitly done by me

use HTML::TreeBuilder; my $row_html = '<!DOCTYPE html> <body> <p>test https://www.google.com</p> </body>'; my $html = HTML::TreeBuilder->new; $html->ignore_ignorable_whitespace(0); $html->no_space_compacting(1); $html->store_comments(1); $html->parse($row_html); # i will do some modifications to HTML here my $output_html = $html->as_HTML(undef,undef,{}); print $output_html;

Current Output with HTML and HEAD tags added by TreeBuilder :

<!DOCTYPE html> <html><head></head><body> <p>test https://www.google.com</p> </body> </html>

I was expecting following output (same as input as im not changing anything in HTML as of now) :

<!DOCTYPE html> <body> <p>test https://www.google.com</p> </body>

In reply to How to avoid addition of tags by HTML::TreeBuilder by phoenix007

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.