Subject: | XML::Twig::XPath breaks XML::Twig::Elt->set_text() |
(This is the same issue as in the e-mail I sent earlier. RT came back
sooner than I was expecting.)
I've discovered that set_text('sometext') stops working for twig
elements that are found as descendants of a XML::Twig::XPath twig, but
works fine for XML::Twig twigs. The version in use is 3.32, as
provided by Debian. Both XML::XPath and XML::XPathEngine are present.
I have attached a simple test case extracted from the chunk of my own
project.
If you run that with a XML::Twig::XPath object, you get back:
Query:
#PCDATA...
^^^
Invalid query somewhere around here (I think)
If you switch to just XML::Twig, it works fine (but then you can't use
XPath functions like name() to reduce the search to a single search).
If you use set_pcdata instead of set_text, it stops complaining, but
the change doesn't appear to be actually made, either -- but this may
be a separate bug, since set_pcdata doesn't appear to do anything even
when using XML::Twig (or perhaps I misunderstand what it's supposed to
do).
Using set_cdata() actually modifies the data and works with
XML::Twig::XPath, but isn't what I actually want.
Subject: | twigbug.pl |
#!/usr/bin/perl
use strict; use warnings;
use XML::Twig::XPath;
my $twig = XML::Twig::XPath->new(pretty_print => 'record');
#my $twig = XML::Twig->new(pretty_print => 'record');
$twig->parse(\*DATA);
my @dates;
@dates = $twig->root->findnodes('//dc:date');
push @dates,$twig->root->findnodes('//dc:Date');
#@dates = $twig->root->findnodes("//*[name()='dc:date' or name()='dc:Date']");
#@dates = $twig->root->get_xpath("//*[name()='dc:date' or name()='dc:Date']");
foreach my $dcdate (@dates)
{
print "Changing '",$dcdate->text,"'\n";
$dcdate->set_text('bad date');
# $dcdate->set_pcdata('bad date');
}
$twig->print;
__DATA__
<package version="2.0" xmlns="http://www.idpf.org/2007/opf">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>A Noncompliant OPF Test Sample</dc:title>
<dc:date event="creation">2008-01-01</dc:date>
<dc:Date event="publication">03/01/2008</dc:Date>
<dc:date opf:event="badfebday">2/31/2004</dc:date>
<dc:Date opf:event="YYYY-xx-DD">2009-xx-01</dc:Date>
</metadata>
</package>