Skip Menu |

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

Report information
The Basics
Id: 7058
Status: resolved
Worked: 15 min
Priority: 0/
Queue: XML-Smart

People
Owner: Nobody in particular
Requestors: mercierma [...] yahoo.com
Cc:
AdminCc:

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



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>
From: guest1
You need to use {CONTENT} for XMLSmart will know this is node $xml->{doc}{port}[0]->{CONTENT} = 30; $xml->{doc}{port}[1]->{CONTENT} = 26; $xml->{doc}{port}[2]->{CONTENT} = 27; $xml->{doc}{port}[3]->{CONTENT} = 28; $xml->{doc}{port}[4]->{CONTENT} = 29; Thanks [guest - Thu Jul 22 12:45:44 2004]: Show quoted text
> 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>
[guest - Thu Jul 22 12:45:44 2004]: Will take a look, since your syntax should work! The use of {CONTENT} is just an option!. Show quoted text
> 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>