I tend to have this problem as well. Some clients I need to integrate with keep on sending invalid XML ... the data are in ISO-8859-1, but there's no encoding attribute. This is what I use to "fix" the issue. It's not clean, but what can I do :-(
unless ($strXML =~ m{^\s*<\?xml [^\?]+?encoding\s*=\s*['"]([^'"]*) +['"][^\?]*\?>} # starts by a <?xml ...?> and uc($1) ne 'UTF-8' # and there is something else than UTF-8 ) { print LOGFILE "It claims to be UTF-8.\n\n"; # so it should be UTF-8 yeah? Let's see ... if (!decode_utf8($strXML)) { print LOGFILE "Hey fix the encoding!!! This aint UTF-8!!!\ +n\n"; $strXML =~ s{^\s*(<\?xml [^\?]+?encoding\s*=\s*['"])[^'"]* +(['"][^\?]*\?>)}{$1ISO-8859-1$2} or $strXML = qq{<?xml version="1" encoding="ISO-8859-1"?>\ +n} . $strXML; } }
In reply to Re: More XML-Twig
by Jenda
in thread More XML-Twig
by zacc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |