Re: XML:LibXML::XPathContext problem
Nic Gibson <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
On 20 Jun 2008, at 10:56, Bjoern Hoehrmann wrote:
> * Nic Gibson wrote:
>> According to the docs, I create a new XPathContext object using a
>> 'new' method. Sadly (at least in version 1.66) there is no new
>> method.
>
> How do you know? It is defined in `LibXML.xs` and tested e.g. in
> `30xpathcontext.t`. Does that test pass on your system?
Right. As Bjoern points out, it is defined. So, I dug a little deeper.
Here's the code.
I'm making an assumption that it must be my dodgy code...
sub get_opf_data
{
my $zip = shift; # Archive::Zip object.
my ($opf_member) = grep {$_->fileName =~ /opf$/i} $zip->members;
die "Unable to find an OPF file\n unless ($opf_member);
my $opfdata = $zip->contents($opf_member);
my $opfdoc = eval {$parser->parse_string($opfdata) };
return () if $@; # Don't really care why it can't be parsed.
my $context = XML::LibXML::XPathContext->new($opfdoc);
$context->registerNs("opf", "http://www.idpf.org/2007/opf");
$context->registerNs("dc", "http://purl.org/dc/elements/1.1/");
# Get the important metadata fields.
my $title = $context->findvalue('//dc:title');
my $author = $context->findvalue('//dc:creator');
# Get the URI for each xhtml file in the epub.
my @files = map {$_->value} $context->findnodes('//opf:manifest/
opf:item[@media-type="application/xhtml+xml"]/@href');
return ($title, $author, \@files);
}
Now, the really interesting thing is that this code works just fine
under the debugger...
Can anyone see anything really dodgy there? Look through my logs,
this happened every now and again under 1.65 but happens consistently
under 1.66
cheers
nic
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs