Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^9: LibXML setNodeName error

by haukex (Archbishop)
on Jun 27, 2017 at 14:57 UTC ( [id://1193704]=note: print w/replies, xml ) Need Help??


in reply to Re^8: LibXML setNodeName error
in thread LibXML setNodeName error

A thorough read of XML-LibXML is probably in order - long, I know, but that's the best way to learn about all the possibilities that are offered :-)

In this case, have a look at ->toFile in XML::LibXML::Document.

Replies are listed 'Best First'.
Re^10: LibXML setNodeName error
by Anonymous Monk on Jun 27, 2017 at 15:03 UTC
    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.
      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');

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found