stevensun has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm trying to parse an XML document. I keep getting the following error on these two records:

"Wide character in print at..."

I did some research but couldn't figure out what this means. I know it has to do with the special characters but not sure how to handle them. I'm trying to parse the info out and then print it to a textfile.

Thanks in advance!

XML: <list> <article>The Doctor&#8217;s Field Manual</article> <article>Technician&#x2019;s Introduction</article> </list>

I'm using:

use XML::Twig; use XML::XPath; use XML::XPath::XMLParser; use XML::Twig::XPath; my $xpathTitle = "//article"; my @title = $twig->find_nodes ($xpathTitle); $Title = $title[0]->text(); print $Title; #this is where the error occurs

Replies are listed 'Best First'.
Re: how to handle special characters in XML?
by mirod (Canon) on Mar 14, 2006 at 09:14 UTC

    Those are not errors, but warnings. print is letting you know that it is trying to print a unicode character to a non-unicode filehandle. Your console is not seen as a unicode filehandle. You can fix this by stating that you want STDOUT to be considered a unicode filehandle by adding the following line before the print:

    binmode STDOUT, ":utf8";

    BTW a few of comments:

    • you only need to use XML::Twig::XPath, not the other modules, they are used in turn by XML::Twig::XPath.
    • your code is not correct, you don't create $twig, posting a complete code example, using strict and warnings, and if possible getting the data from the DATA section so it's self-contained would make the life of people responding to your question a little easier,
    • why the high unicode characters instead of plain old ' (although you might not have control over that),
    • finally, a google search on perl "wide character in print" would have given you the answer quicker.