LibXML document->toString vs element->toString

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi, I have been driven mad by the following, which took ages to track
down. What is going on? I appears it is invalid to use toString on the
document object.

#! /usr/local/bin/perl -w
use strict;
use warnings;
use utf8;
use Encode;
use XML::LibXML;
binmode(STDOUT, ":utf8");

 my $src= join("",<DATA>);
 print "string $src is invalid \n" unless ( Encode::is_utf8($src,1) );
 my $parser = XML::LibXML->new();
 my $x = $parser->parse_string($src)->documentElement();
 my $str=$x->toString(1);
 print "$str\n";
 print "string 1 is invalid \n" unless ( Encode::is_utf8($str,1) );

 $x = $parser->parse_string($src);
 print "$str\n";
 print "string 2 is invalid \n" unless ( Encode::is_utf8($str,1) );

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<plugin name="\xc5\x81"></plugin>

Site Timeline