How to use Perl's XML::XPath with non-English element names?

Viewed 280

How can I work with XML::XPath when some elements' names are not in English?

I use Strawberry Perl.

I get employees.xml and train_xml.pl from web, they work good.

But when When I add some Chinese characters, I get the following error:

Wide character in die at D:/Strawberry/perl/site/lib/XML/XPath/Parser.pm line 189.

Query:
/employees/employee[@age="30"]/工作...
..............................^^^
Invalid query somewhere around here (I think)

How can I solve this?

employees.xml:

<?xml version="1.0" encoding="utf-8" ?>
<employees>
    <employee age="30">
        <name>linux</name>
    <country>US</country>
    <工作>教师</工作>
    </employee>
    <employee age="10">
    <name>mac</name>
    <country>US</country>
    </employee>
    <employee age="20">
    <name>windows</name>
    <country>US</country>
    </employee>
</employees>

train_xml.pl:

use Encode;
use XML::XPath->new;
use utf8;
my $xp=XML::XPath->new(filename=>"employees.xml");
print $xp->findvalue('/employees/employee[@age="10"]/name'),"\n";
my $path1 = '/employees/employee[@age="30"]/工作';
print $xp->findvalue($path1),"\n";
2 Answers
Related