Resolved!
The reading is very dense.
I quickly found:
my $file = 'output.xsl';
open my $out_fh, '>', $file;
print {$out_fh} $doc->toString;
Thank you for all your help and your patience. I'm glad to be a new member of this community, and I promise to give back in the future just as you have given to me. | [reply] [d/l] |
open my $out_fh, '>', $file;
print {$out_fh} $doc->toString;
Unfortunately I have to say that this is not the best solution. The reason is that the encoding you are opening the file with has to match the XML document's encoding, which ->toFile handles for you. The following will produce two different files, only the second one being encoded correctly (as ISO-8859-15). Since it seems to me that you are not generating the files yourself but are reading existing files, it's not impossible that one of them has an encoding other than UTF-8.
use warnings;
use strict;
use XML::LibXML;
use open qw/:std :utf8/;
my $xml = <<'END_XML';
<?xml version="1.0" encoding="ISO-8859-15"?>
<foo></foo>
END_XML
my $doc = XML::LibXML->load_xml(string => $xml) or die;
$doc->documentElement->appendText("\x{20AC}");
open my $fh, '>', '/tmp/one.xml' or die $!;
print $fh $doc->toString;
close $fh;
$doc->toFile('/tmp/two.xml');
| [reply] [d/l] [select] |