in reply to Re: XML:: DOM and Accented Characters
in thread XML:: DOM and Accented Characters

Hi ikegami

I've tried selecting utf8 in editor menus and inserting a BOM but neither has seemingly worked. I think my files are coming out windows-1252 encoded because without runnig the code you provided and just changing the 1st line to

<?xml version="1.0" encoding="windows-1252"?>

results in me being able to open the file OK

What is confusing me is that running the code below

#!/bin/perl -w use XML::DOM; use PerlIO::encoding; my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile ("c:\\accentTest.xml", ProtocolEncoding = +> 'UTF-8'); # Print doc file $doc->printToFile ("c:\\accentTestOutPut.xml"); open my $fh, ">:encoding(UTF-8)", "accentTestOutPut.xml" or die $!; $doc->print($fh); $doc->dispose;

In windows results in a file (that to my untrained eye) appears to not be UTF8 encoded (in hex I do not see the C3 A9 for the e-acute) and will not open without the above mentioned 1st line change, however

If I run the same code in Unix and open the resulting file in windows its all fine. It appears properly utf8 encoded and viewing the file in hex shows the C3 A9 expected for the e-acute

At the moment I'm not understanding why the problem is with the editors (not saying it isn't just don't understand why yet). Whats confusing me is the file created using the same code on Unix opens without issue?

Replies are listed 'Best First'.
Re^3: XML:: DOM and Accented Characters
by ikegami (Patriarch) on Aug 09, 2010 at 13:51 UTC

    I think my files are coming out windows-1252 encoded

    You think? I gave you a tool to check. I also asked that you check your input file.

      badly worded, I've got it sorted now. Thanks for the time but the problem was down to me not noticing something incredibly obvious. The issue was I hadn't noticed the filepath when opening the filehandle in the code I gave had the C:\\ knocked off, so the resulting file was being saved elsewhere. I only noticed after almut got me to take out the printToFile method

      Incredibly stupid but I've learn't a lot more by leading myself down the garden path