I'm sorry to say that while I can't provide you with a solution, I can at least verify that something is going wrong with the unicode strings. However, in my tests (Mac OS 10.3.7 and libxml 2.2.6 with XML::LibXML 1.58) I am getting well-formed XML in both output. Using your example, I have verified that while toFile properly displays:

<?xml version="1.0" encoding="utf-8"?>
<MSG>*Ä*</MSG>

when I changed your code to print the result of toString to a file, I got

<?xml version="1.0" encoding="utf-8"?>
<MSG>*?*</MSG>

What versions of Perl and XML::LibXML/libxml2 are you running? (Note: I'm very much a noob when it comes to unicode)

On Feb 9, 2005, at 8:05 AM, [EMAIL PROTECTED] wrote:

Lo all,

I was having some trouble with my axkit app and have tracked it
down to this.
I've googled for a solution/explanation and got about 4 pages ie
nowhere.
When the code below is run the xml is not well formed.
To be more precise, the output via toString isn't well formed, the
output via toFile _is_ well formed.
What seems to happening is that toString is decoding the utf string
\x{C3}\x{84} for some reason. toFile does not do this.
This is either a bug, a feature or, as is more likely, my lack of
understanding.
If someone could be so kind as to point me in the right direction it
would be appreciated.

John



#!/usr/bin/perl -w

use strict;
use diagnostics;
use XML::LibXML;
use Encode qw (encode encode_utf8 decode_utf8 is_utf8 from_to
_utf8_on);

binmode(STDOUT,":raw");

my $data = "*\x{C3}\x{84}*";

my $dom = XML::LibXML::Document->createDocument('1.0', 'utf-8');

my $node = $dom->createElement('MSG');

my $text = $dom->createTextNode( $data );
$node->addChild($text);

print is_utf8($data);

$dom->setDocumentElement( $node );

my $aa = $dom->toString(0);

print $aa,"\n";

$dom->toFile('aa',0);


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to