Skip Menu |

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

Report information
The Basics
Id: 125515
Status: new
Priority: 0/
Queue: XML-Twig

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

Bug Information
Severity: Wishlist
Broken in: 3.52
Fixed in: (no value)



Subject: Provide a way to exclude tags from a twig-wide trim()
The twig-wide trim() function is a great way to clean up ugly XML! However, some tags (in my case, <pre></pre>) need to be excluded from trimming. I'm not sure if $elt->set_as() is appropriate to indicate exclusion, or if it's orthogonal and a separate set_trim() is needed instead; this is left to the developer's discretion. (Side note: trim() leaves single spaces at the beginnings and ends of non-head, non-tail tags that are trimmed. It would be nice not to have these.)
Subject: trim.pl
#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $xml = <<EOF; <?xml version="1.0" encoding="UTF-8"?> <html> <body> <p> This is some text. </p> <p> This is some text. </p> <pre> This is preformatted text. </pre> <p> This is some text. </p> <p> This is some text. </p> </body> </html> EOF my $twig=XML::Twig->new; $twig->setTwigHandlers({ 'pre' => sub { $_->set_asis(); }, }); $twig->parse($xml); $twig->trim; $twig->print(pretty_print => 'indented');