Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created June 10, 2009 09:16
Show Gist options
  • Save lestrrat/127112 to your computer and use it in GitHub Desktop.
Save lestrrat/127112 to your computer and use it in GitHub Desktop.
use strict;
use utf8;
use XML::LibXML;
use Encode;
my $xml = encode('euc-jp', <<EOXML);
<?xml version="1.0" encoding="euc-jp"?>
<foo>
<bar attr="日本語">日本語のbar</bar>
</foo>
EOXML
print "XML -> $xml\n";
my $dom = XML::LibXML->new->parse_string($xml);
my $xpath = encode('euc-jp', '/foo/bar[@attr="日本語"]/text()');
print "XPath -> $xpath\n";
my @nodes = $dom->findnodes($xpath);
use Data::Dumper;
print Dumper(@nodes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment