sub xml_compliance { my ($self, $field) = @_; my $fixed = ""; my $h_translate = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => ''', }; my @chars = split //, $field; foreach my $char (@chars) { if (exists $h_translate->{$char}) { $fixed .= $h_translate->{$char}; } elsif (ord($char) > 0x7f) { # This is where we handle all non 7-bit ascii $fixed .= sprintf "&#%02x;", ord($char); } else { $fixed .= $char; } } return $fixed; }