Skip Menu |

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

Report information
The Basics
Id: 18956
Status: resolved
Priority: 0/
Queue: XML-Smart

People
Owner: TMHARISH [...] cpan.org
Requestors: perlstar [...] yahoo.com
Cc:
AdminCc:

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



Subject: empty arrays show 1, not 0
I have attached a small sample program (which might be the basis of a helpful addition to the XML::Smart package documentation, BTW) that prints out some inventory items. The output of this program: found 2 tricycles you have: 5 blue tricycles you have: 2 red tricycles found 1 bicycles you have: 3 yellow bicycles found 1 rollerskates you have: 0 found 1 bananapeels you have: 0 I say that it should not print the "rollerskates" line or the three lines following. Steve Vance, perlstar@yahoo.com
Subject: xml4.pl
# Test of XML::Smart # 2006/04/27 Thu # questions or comments: perlstar@yahoo.com use XML::Smart; my $xmlData = XML::Smart->new( \*DATA ); foreach $vehicle ( keys %{ $xmlData->{Inventory}{vehicles} } ) { print "vehicle found: $vehicle \n"; } print "-------------\n"; foreach $thing ('tricycles', 'bicycles', 'rollerskates', 'bananapeels') { print "found ", scalar @{ $xmlData->{Inventory}{vehicles}->{$thing}{item} }, " $thing\n"; foreach $item ( @{ $xmlData->{Inventory}{vehicles}->{$thing}{item} } ) { print " you have: ", 0 + $item->{qty}, " $item->{name} \n"; } } __DATA__ <?xml version="1.0" encoding="utf-8"?> <Inventory xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <vehicles> <tricycles> <item> <qty>5</qty> <name>blue tricycles</name> </item> <item> <qty>2</qty> <name>red tricycles</name> </item> </tricycles> <bicycles> <item> <qty>3</qty> <name>yellow bicycles</name> </item> </bicycles> <rollerskates /> </vehicles> </Inventory>
Expected Behavior scalar @{ $xmlData->{Inventory}{vehicles}->{$thing}{item} } will return 1 as the array has one element. Use qty within your data to do this check instead.