Subject: | XML::Twig and whitespaces in element values and in attribute values |
Date: | Thu, 23 Aug 2007 17:37:27 +0300 (IDT) |
To: | bug-XML-Twig [...] rt.cpan.org. |
From: | Yona Shlomo <yona [...] cs.technion.ac.il> |
Hello,
This is the same issue that was reported at
http://www.perlmonks.org/?node_id=634644
Here's the issue:
I'm using XML::Twig and have noticed that it replaces
white-space characters to spaces. Something like s/\s/ /g on
all attribute and element values.
See example code:
#!/usr/bin/perl use strict;
use warnings;
use XML::Twig;
my $twig=XML::Twig->new();
my $xml = qq{<root t="space tab\tnewline\nend"/>};
$twig->xparse($xml);
my $text=$twig->root->att('t');
print "|$text|\n";
The expected output (contents of the scalar $text is the
word space followed by a single space character, followed by
the word tab, followed by a single tab character, followed
by the word newline, followed by a single newline character,
and then the word end.
Instead, the tab and the newline characters were replaced by
a single space character each.
1. Why?
2. How can I force XML::Twig to preserve whitespaces and not
alter the text in any form?
This relates to XML::Twig 3.29 and XML::Twig 3.30. I did not
check this behavior in other versions of XML::Twig
Thanks.
--
Shlomo Yona
yona@cs.technion.ac.il
http://yeda.cs.technion.ac.il/~yona/