Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: XML::Simple and ISO-8859-1 encoding buggy?

by cavac (Parson)
on May 27, 2021 at 07:11 UTC ( [id://11133105]=note: print w/replies, xml ) Need Help??


in reply to XML::Simple and ISO-8859-1 encoding buggy?

After some testing I assume that XML::Simple simply does not care about the declared encoding because the following works.

Frankly, i have seen enough XML files where the declared encoding is not matching the actual encoding. While your case might or might not be an XML::Simple problem, trusting the declared encoding is not much better...

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

Replies are listed 'Best First'.
Re^2: XML::Simple and ISO-8859-1 encoding buggy?
by derion (Sexton) on May 27, 2021 at 08:53 UTC

    I did not yet find a way to automatically determine the encoding of a file/data but would be very happy to have something for a at least good guessing.

    In my case I downloaded the file, opened it with Notepad++, the special characters were displayed as they should and Notepadd++ showed the information that the file is ISO-8859-1.
    Nevertheless I dare not say that the encoding could not be something else.

      I did not yet find a way to automatically determine the encoding of a file/data but would be very happy to have something for a at least good guessing.

      While sadly files with unknown encodings are not rare, IMHO guessing encodings should be a matter of last resort, much better is to find out how the files were generated and get their encoding from there. But if you really don't know the encoding of the input files, you could use a module like Encode::Guess, or I've written a tool that tries to be a little smarter: enctool - it allows you to narrow down the guesses by specifying what characters are expected to appear in the input file using e.g. the --one-of='\xFC' option (which in this case will look for U+00FC LATIN SMALL LETTER U WITH DIAERESIS ("ü"); you can specify multiple possible characters).

      And I must second the opinion that XML::Simple shouldn't be used. For full-fledged XML support, I'd suggest XML::LibXML, or for a XML::Simple replacement, have a look at XML::Rules.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found