You can use XML::Smart with it's own parser, and printing data() with the wild option:
use XML::Smart ; my $XML = new XML::Smart(q{ <html> <head> <title> test </title> </head> <body bgcolor='red' > <errors> <TMPL_IF NAME='INVALID_WIDGET_SIZE' > waka waka </TMPL_IF> <TMPL_IF NAME='INVALID_WIDGET_COLOR' > waka waka waka </TM +PL_IF> </errors> <table> <tr colspan='2'> <td> text </td> <td> text2 </td> </tr> </table> </body> </html> } , XML::Smart::Parser) ; print $XML->data(wild=>1 , noheader=>1) ;
Output:
<html> <body bgcolor="red"> <errors> <TMPL_IF NAME="INVALID_WIDGET_SIZE"> waka waka </TMPL_IF> <TMPL_IF NAME="INVALID_WIDGET_COLOR"> waka waka waka </TMPL_IF> </errors> <table> <tr colspan="2"> <td> text </td> <td> text2 </td> </tr> </table> </body> <head title=" test "/> </html>
But note that XML and HTML are different! One thing you can see is the order of the tags and the title that works like an attribute. You can control how the data() method will trate the entry as an attribute or node with some extra flags, but is not good to do this always! I think that the best option is to use some HTML::* module like HTML::TokeParser, as other monks already have said.

Graciliano M. P.
"The creativity is the expression of the liberty".


In reply to Re: XML::Simple problem, or How to convert HTML to Perl and then back again. by gmpassos
in thread XML::Simple problem, or How to convert HTML to Perl and then back again. by Wonko the sane

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.