このXMLを処理するためにXML::Twigを使用しています:
<?xml version="1.0" encoding="UTF-8"?>
<termEntry>
<langSet lang="en">
<ntig>
<termGrp>
<term>trail</term>
<termNote type="partOfSpeech">noun</termNote>
</termGrp>
<descrip type="context">Like in a forest</descrip>
</ntig>
</langSet>
</termEntry>
私はそれを処理するために次のコードを使用しています:
use strict;
use XML::Twig;
my $twig_handlers = {
termEntry => sub { for my $node($_[1]->findnodes('.//descrip|.//termNote')){print $node->text;}},
};
my $twig= new XML::Twig(
TwigRoots => { termEntry => 1},
TwigHandlers => $twig_handlers,
);
$twig->parsefile('C:\Users\me\file.xml');
コードは次のように失敗します:
error in xpath expression .//descrip|.//termNote around descrip|.//termNote at
C:\Users\nate\Desktop\test.pl line 6
私はさまざまなことを試みてきましたが、いつでも「|」を使用します xpathの文字は、プログラムを壊します。http://www.xpathtester.comで問題なく動作します(「。」を「//」に置き換えたと思います)。これを修正する方法について何かアイデアはありますか?