Subject: | Bug in XML::Smart |
When using the array option to add elements to an xml file, if you start at index 0, it only seems to add correctly for index 0 and 1. It then begins adding the elements as attributes of the parent tag. If you start at index 1 and write index 0 last, everything seems to work correctly.
Code included to reproduce error:
XML-Smart-1.6.6
v5.8.3 built for MSWin32-x86-multi-thread (ActiveState)
Windows 2000 Service Pack SP3
Original XML Document used for test
<?xml version="1.0" encoding="UTF-8"?>
<doc type="test">
<data>test 1</data>
<data>test 2</data>
<data>test 3</data>
<file>file 1</file>
</doc>
Example 1:
#!/usr/bin/perl -w
use XML::Smart;
use Data::Dumper;
my $xml = new XML::Smart('c:\\mike\\test.xml', lowtag => 1);
$xml->{doc}{port}[1] = 26;
$xml->{doc}{port}[2] = 27;
$xml->{doc}{port}[3] = 28;
$xml->{doc}{port}[4] = 29;
$xml->{doc}{port}[0] = 30;
print $xml->data();
Output:
<?xml version="1.0" encoding="utf-8" ?>
<?meta name="GENERATOR" content="XML::Smart/1.6.6 Perl/5.008003 [MSWin32]" ?>
<doc type="test">
<data>test 1</data>
<data>test 2</data>
<data>test 3</data>
<file>file 1</file>
<port>30</port>
<port>26</port>
<port>27</port>
<port>28</port>
<port>29</port>
</doc>
Example2:
#!/usr/bin/perl -w
use XML::Smart;
use Data::Dumper;
my $xml = new XML::Smart('c:\\mike\\test.xml', lowtag => 1);
$xml->{doc}{port}[0] = 30;
$xml->{doc}{port}[1] = 26;
$xml->{doc}{port}[2] = 27;
$xml->{doc}{port}[3] = 28;
$xml->{doc}{port}[4] = 29;
print $xml->data();
port shows up as an attribute of the <doc> tag after index 1
Output:
<?xml version="1.0" encoding="utf-8" ?>
<?meta name="GENERATOR" content="XML::Smart/1.6.6 Perl/5.008003 [MSWin32]" ?>
<doc type="test" port="27" port="28" port="29">
<data>test 1</data>
<data>test 2</data>
<data>test 3</data>
<file>file 1</file>
<port>30</port>
<port>26</port>
</doc>