Re: enabling utf8 encoding for sax parer XML::SAX::Expat
Michael Ludwig <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
eyal edri schrieb: > On Wed, Apr 29, 2009 at 11:19 AM, Michael Ludwig <[email protected]> > wrote: > >> eyal edri schrieb: >> >>> can it be that since i'm using LWP::UserAgent , perl somehow changes >>> the encoding while d/l? >> Just ran into this myself. I think LWP does that, not Perl. And it >> may even be the correct thing to do, given that what you send over >> the wire are octets, not strings. See the note in the perldoc for >> HTTP::Request: As Robin has suggested, I mistakenly identified the issue you're having with another one I had just ran into myself which had to do with POSTing a document, which is probably unrelated to your problem. > So you think that if i'll save the $resp->content in memory and then > save it to file using >:encoding(utf-8) it will fix the wrong file > encoding ? (assuming lwp does change the file encoding while d/l?) No, I don't think that will help. The correct encoding should be specified in the Content-Type header of the response, like this: Content-Type: text/xml; charset=utf-8 You can access the decoded string of bytes using one of: $r->decoded_content( %options ) # HTTP::Response $mess->decoded_content( %options ) # HTTP::Message, base class But this applies the information in the response headers, and cannot magically divine the correct encoding. If both Content-Type header and XML declaration are either missing or incorrect, this is a broken service, and to repair it, you have to resort to what Robin suggested, and failing that, apply low-level techniques, but I would rather complain to the service provider. Michael Ludwig _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs