output:use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new( pretty_print => 'indented', twig_handlers => { TMPL_IF => sub { my ($t, $TMPL_IF) = @_; $TMPL_IF->set_text( 'changed it' ); } } ); $twig->parse(\*DATA); $twig->print; __DATA__ <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 </TMPL_IF> </errors> <table> <tr colspan='2'> <td> text </td> <td> text2 </td> </tr> </table> </body> </html>
Here, XML::Twig is simply used as a filter, but once your XML is parsed in the $twig object, you can easily access the elements and change their content/tag/attributes.<html> <head> <title> test </title> </head> <body bgcolor="red"> <errors> <TMPL_IF NAME="INVALID_WIDGET_SIZE">changed it</TMPL_IF> <TMPL_IF NAME="INVALID_WIDGET_COLOR">changed it</TMPL_IF> </errors> <table> <tr colspan="2"> <td> text </td> <td> text2 </td> </tr> </table> </body> </html>
In reply to Re: XML::Simple problem, or How to convert HTML to Perl and then back again.
by choocroot
in thread XML::Simple problem, or How to convert HTML to Perl and then back again.
by Wonko the sane
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |