1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
use strict;
use warnings;
=head1 DESCRIPTION
If an element contains both a default namespace declaration and a second
namespace declaration, adding an attribute using the default namespace
declaration will cause that attribute to have the other prefix.
OS Version: FreeBSD 6.3-RELEASE
Perl Version: v5.8.8
LibXML Version: 1.70
See L<https://rt.cpan.org/Ticket/Display.html?id=55000> .
=cut
use Test::More tests => 6;
use XML::LibXML;
my $xml_string = <<'XML';
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns="uri"
xmlns:wrong="other">
</element>
XML
my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($xml_string);
my $root = $doc->documentElement();
$root->setAttributeNS("uri", "prefix:attribute", "text");
$root->setAttributeNS("uri", "second", "text");
my $string = $doc->toString(1);
# TEST
unlike ($string, qr/[^\w:]attribute="text"/,
"Not placed as an unprefixed attribute");
# TEST
unlike ($string, qr/\bwrong:attribute="text"/,
"Not placed in the wrong namespace");
# TEST
like ($string, qr/\bprefix:attribute="text"/,
"Placed in the right namespace");
# TEST
unlike ($string, qr/[^\w:]second="text"/,
"Not placed as an unprefixed attribute");
# TEST
unlike ($string, qr/\bwrong:second="text"/,
"Not placed in the wrong namespace");
# TEST
like ($string, qr/\bprefix:second="text"/,
"Placed in the right namespace");
|