Some UTF-8 characters hereí
Some more UTF-8 characters hereč
±There could be UTF-8 characters anywhere
]]>
#### encode_entities( $youaretheoneiwantValue , '&\'"[]\200-\377' ); #### #!/usr/bin/perl use strict; use warnings; use utf8; use XML::Twig; use HTML::Entities; use HTML::Parser; my $xml = $ARGV[0] or die "Usage: format_html_nicely.pl XML_DATA\n"; #print $xml; my $twig = XML::Twig->new( pretty_print => 'indented', twig_handlers => { property => \&encodeCorrectly }); $twig->parse( $xml ); $twig->flush; exit; sub encodeCorrectly { my( $twig, $property)= @_; if($property->att('name') eq 'youaretheoneiwant') { my $htmlToEncode = $property->text; my $htmlEncoded encode_entities( $htmlToEncode , '&\'"[]\200-\377' ); #print "\n\n\n\n\n" . $htmlEncoded ."\n\n\n\n\n"; $property->set_text( $htmlEncoded ); #print "\n\n\n\n\n" . $property->text ."\n\n\n\n\n"; $twig->flush; } }