Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

XML encoding ISO-8859-1

by Anonymous Monk
on Aug 23, 2001 at 12:55 UTC ( [id://107273]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have an xml file encoded in ISO-8859-1. I parse it with XML::DOM::Parser. Then I extract some of the text and Attribute Values using methods of XML::DOM::Node. The problem is that the strings I get with these methods are encoded in UTF-8 and all special characters (vowels with accents, german umlauts,...) are garbled. Is there any way to set the encoding of the strings you get from the Node class?

Replies are listed 'Best First'.
Re: XML encoding ISO-8859-1
by mirod (Canon) on Aug 23, 2001 at 13:39 UTC

    There is no way to set the encoding for the strings, you will have to convert them.

    Search for Unicode or character conversion or encoding and you will find tons of nodes describing how to go from UTF-8 to ISO-8859-1 (use Text::Iconv).

Re: XML encoding ISO-8859-1
by stefan k (Curate) on Aug 23, 2001 at 13:09 UTC
    Please correct me if I'm wrong. I always thought if the XML file is encoded in one way all it's contents should be coded like that. Maybe you should change it file's encoding style to UTF-8?

    But then ... maybe I'm just plain wrong in this case and always understood things wrong?

    Regards... Stefan

      You are right in that all of the file is encoded in ISO-8859-1 and I account for this by setting the ProtocolEncoding of the Parser. The problem is, that the strings I get *back* from the Parser are NOT in the same encoding, but in UTF-8 (it says so somewhere in the documentation). Changing the encoding of the input file would be an option, but how do I do this? Just putting 'encoding="UTF-8"' into the XML declaration does not work, because then I get malformedness errors (because the input file is not in UTF-8). Robert

Log In?
Username:
Password:

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

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

    No recent polls found