Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: ralphmerridew [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.38
Fixed in: (no value)



Subject: discard_spaces being ignored
Download (untitled) / with headers
text/plain 248b
If the XML contains whitespace at certain spots, it won't pretty-print. Isn't the discard_spaces option supposed to prevent that? To trigger error, run script as attached. To prevent, change the 1 to a 0. perl v.5.12.2, MSWIN32-x86-multi-thread
Subject: test-xml-4.pl
Download test-xml-4.pl
text/x-perl 323b
use strict; use XML::Twig; my $twig = XML::Twig->new(pretty_print => 'indented', #keep_spaces => 0, discard_spaces => 1, comments => 'drop', ); my $space = 1 ? " " : ""; my $file = "<d><title section='1'>title</title><para>p 1</para>${space}<para>p 2</para></d>"; $twig->parse($file)->print;
Subject: Re: [rt.cpan.org #71164] discard_spaces being ignored
Date: Fri, 23 Sep 2011 10:13:13 +0200
To: bug-XML-Twig [...] rt.cpan.org
From: mirod <xmltwig [...] gmail.com>
Download (untitled) / with headers
text/plain 1.4k
On 09/22/2011 06:47 PM, Mark Tilford via RT wrote: Show quoted text
> Thu Sep 22 12:47:00 2011: Request 71164 was acted upon. > Transaction: Ticket created by ralphmerridew@gmail.com > Queue: XML-Twig > Subject: discard_spaces being ignored > Broken in: 3.38 > Severity: Normal > Owner: Nobody > Requestors: ralphmerridew@gmail.com > Status: new > Ticket<URL: https://rt.cpan.org/Ticket/Display.html?id=71164> > > > If the XML contains whitespace at certain spots, it won't pretty-print. > Isn't the discard_spaces option supposed to prevent that? > > To trigger error, run script as attached. > To prevent, change the 1 to a 0. > > perl v.5.12.2, MSWIN32-x86-multi-thread
That's the normal behavior: your xml boils down to '<d><para>p 1</para> <para>p 2</para></d>', which as the same structure as, for example, '<p><b>Hello</b> <i>World!</i></p>', where obviously you would not want to discard the space between b and i. The space would be discarded if it included a \n, try with <d><para>p 1</para>\n <para>p 2</para></d> The documentation is unclear about this, so I have updated it in the development version of the module. i have also added a 'discard_all_spaces' option, that discards spaces more aggressively, namely it will discard all-space strings before a tag (opening or closing), whether they include a \n or not. This would allow indenting of your document. The development version is in the usual places, http://xmltwig.org/xmltwig/ and http://github.com/mirod/xmltwig -- mirod
fixed in 3.40 __ mirod


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.