Skip Menu |
 

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 39828
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: AZED [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.32
Fixed in: 3.33



Subject: XML::Twig::XPath breaks XML::Twig::Elt->set_text()
MIME-Version: 1.0
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Charset: utf8
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1223250360-4238-5"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 1124
(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
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1223250360-4238-4"
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: text/x-perl; name="twigbug.pl"
Content-Disposition: inline; filename="twigbug.pl"
Content-Transfer-Encoding: binary
Content-Length: 1098
Download twigbug.pl
text/x-perl 1k
#!/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>
MIME-Version: 1.0
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-4236-1223280535-1191.39828-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 664
Download (untitled) / with headers
text/plain 664b
It seems this bug is already fixed in the development version at http://xmltwig.com/xmltwig (and no, I can't figure out why!). Let me know if it works for you. You also mentioned problems with findnodes, get_xpath and find_nodes in your email: if get_xpath or find_nodes is called and fails, while the twig is an XML::Twig::XPath, I will make sure that the error message mentions the fact that findnodes might be different. I only replaced findnodes because originaly, before I created XML::XPathEngine, "native" regexp matching ( /foo[string()=~ /^toto/]) wasn't available, so I gave the option to still be able to use the original methods. Thanks __ mirod
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-4236-1223280535-1191.39828-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Content-Disposition: inline
Charset: utf8
References: <rt-3.6.HEAD-4236-1223280535-1191.39828-0-0 [...] rt.cpan.org>
Message-Id: <rt-3.6.HEAD-4211-1223307418-1473.39828-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 973
Download (untitled) / with headers
text/plain 973b
I got a couple of odd messages during testing (though all tests that executed passed successfully): option do_not_escape_amp_in_atts not available, probably due to an old version of expat being used: skipping 1 tests and can only test set_strict_namespaces with XML::XPathEngine 0.09+ installed: skipping 12 tests but later down in the configuration it notes that it found: expat : 2.0.1 (required) ... XML::XPathEngine : 0.11 (to use XML::Twig::XPath) XML::XPath : 1.13 (to use XML::Twig::XPath if Tree::XPathEngine not available) That's the latest version of expat that I know of, and XPathEngine is above 0.09. After it was built and installed, however, I ran my original test sample again and set_text() worked fine... but set_pcdata() is still a no-op. Is set_pcdata() supposed to be doing the same thing as set_text for that kind of node? Should I file a separate RT bug for that?
MIME-Version: 1.0
X-Spam-Status: No, hits=-2.6 required=8.0 tests=BAYES_00,DK_SIGNED,SPF_PASS
In-Reply-To: <rt-3.6.HEAD-4211-1223307418-1473.39828-5-0 [...] rt.cpan.org>
References: <RT-Ticket-39828 [...] rt.cpan.org> <rt-3.6.HEAD-4236-1223280535-1191.39828-5-0 [...] rt.cpan.org> <rt-3.6.HEAD-4211-1223307418-1473.39828-5-0 [...] rt.cpan.org>
Reply-To: xmltwig [...] gmail.com
Content-Type: text/plain; charset=UTF-8; format=flowed
X-RT-Original-Encoding: utf-8
Received: from x1.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id 9049263C658 for <bug-XML-Twig [...] rt.cpan.org>; Mon, 6 Oct 2008 12:29:00 -0400 (EDT)
Received: (qmail 19209 invoked from network); 6 Oct 2008 16:28:59 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 6 Oct 2008 16:28:59 -0000
Received: from ey-out-2122.google.com (HELO ey-out-2122.google.com) (74.125.78.27) by 16.mx.develooper.com (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Oct 2008 09:28:51 -0700
Received: by ey-out-2122.google.com with SMTP id 25so823802eya.27 for <bug-XML-Twig [...] rt.cpan.org>; Mon, 06 Oct 2008 09:28:48 -0700 (PDT)
Received: by 10.210.22.8 with SMTP id 8mr6570262ebv.98.1223310528161; Mon, 06 Oct 2008 09:28:48 -0700 (PDT)
Received: from ?192.168.2.200? ([217.133.3.216]) by mx.google.com with ESMTPS id 32sm6681816nfu.10.2008.10.06.09.28.44 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 06 Oct 2008 09:28:46 -0700 (PDT)
Delivered-To: cpan-bug+XML-Twig [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #39828] XML::Twig::XPath breaks XML::Twig::Elt->set_text()
User-Agent: Thunderbird 2.0.0.17 (X11/20080914)
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; b=s+JQ64sLFLNuYq7kDExmfvHmWySGSNCm6eOewNA5nvWprWTfIr2mHm8D3JRi9XBQ4P fEitH4lfBSc2d8fDtC8W+7Tft960/x7zRTsnkJcNHYivP7VFydKS2yEINEEoIabfCIDs kBj5/M5Uz76FaCZphYssWV7mu0Vl8qYuV+Pp0=
Return-Path: <xmltwig [...] gmail.com>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=p9vjxoG0+076b4NIZIMlhxJlLY8p2TgnrBo0OxBNaZo=; b=Hrq5evvcISYLpl7dqqvIcRt2uX+vi57LVYOloUpG559VFBnBZfTn7RLeobIYwTw9Rc RM3vk4tPZZqaha7CjOWEA7bV85feFBHIhkrzfAKPMVdOkTtEhgp4Q1+3hViW3NLfJBaY M7Uuu7iXgm2P4FU9vUhoJcFaqp0yziF0iBXxI=
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-XML-Twig [...] rt.cpan.org
Date: Mon, 06 Oct 2008 18:28:55 +0200
X-Spam-Level: *
Message-Id: <48EA3CC7.7000607 [...] gmail.com>
To: bug-XML-Twig [...] rt.cpan.org
Content-Transfer-Encoding: 7bit
From: mirod <xmltwig [...] gmail.com>
RT-Message-ID: <rt-3.6.HEAD-4226-1223310553-848.39828-0-0 [...] rt.cpan.org>
Content-Length: 1895
Download (untitled) / with headers
text/plain 1.8k
Zed Pobre via RT wrote: Show quoted text
> Queue: XML-Twig > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=39828 > > > I got a couple of odd messages during testing (though all tests that > executed passed successfully): > > option do_not_escape_amp_in_atts not available, probably due to an old > version of expat being used: skipping 1 tests
Yes, I get this one too at the moment. The seldom used do_not_escape_amp_in_atts cannot be used with old... and very recent versions of expat. I have to investigate this one, or at least change the warning Show quoted text
> can only test set_strict_namespaces with XML::XPathEngine 0.09+ > installed: skipping 12 tests
Weird. I don't get this one. The test is not done on the version of XML::XPathEngine, but on the fact that XML::Twig::XPath offers the set_strict_namespaces method. Show quoted text
> > but later down in the configuration it notes that it found: > > expat : 2.0.1 (required) > ... > XML::XPathEngine : 0.11 (to use XML::Twig::XPath) > XML::XPath : 1.13 (to use XML::Twig::XPath if > Tree::XPathEngine not available) > > That's the latest version of expat that I know of, and XPathEngine is > above 0.09. > > After it was built and installed, however, I ran my original test sample > again and set_text() worked fine... but set_pcdata() is still a no-op. > Is set_pcdata() supposed to be doing the same thing as set_text for > that kind of node? Should I file a separate RT bug for that?
Using set_pcdata on a non-text element is useless, unless you set the tag name to '#PCDATA'. Bottom line, you should use set_text. And I should have added an error check a while ago, except that now I am not sure it's really possible, as people might be relying on that behaviour (and indeed first set_pcdata then set_tag( '#PCDATA')). I have at least changed the docs. Thanks


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.