From: Chris <chr...@ya...> - 2012-09-17 20:56:45
|
Hello, I am hoping someone can see what is wrong with my code. I am trying to write an XML file from values in my weather hash, but I get XML file with just the root name and no content. I has used similar code else where and it works. I have tried substituting the hash with numeric values and that works. What is odd, at least to me is that I added the code to write a JSON file and it does show the data I expectd. I am really at a loss on this. Thanks for any help. Regards, Chris Here is the code and then the output: # Category Environment #@ This is for creating an xml file of current status use XML::Simple qw(XMLout); use Data::Dumper; use JSON; my %arr; if ($New_Minute){ print_log "got here"; print_log "Light level $Weather{LightLevel} wind $Weather{WindDir} $Weather{WindSpeed}"; open (XMLFILE, '>/var/www/html/weather.xml'); # create array %arr =( 'Time'=>$Time_Now, 'Date'=>$Date_Now, 'TempOutside'=>$Weather{TempOutdoor}, 'TempGarage'=>$Weather{TempGarage}, 'TempIn1'=>$Weather{TempIndoor}, 'RelHumid1'=>$Weather{RelHumid}, 'Radiance'=>$Weather{LightLevel}, 'MaxTemp'=>$Weather{TempOutdoorHigh}, 'MinTemp'=>$Weather{TempOutdoorLow}, 'ForCastHigh'=>$Weather{ForCastHi}, 'ForCastLow'=>$Weather{ForCastLo}, 'ForCast'=>$Weather{Forcast}, 'WindSpeed'=>$Weather{WindSpeed}, 'SkyCondition'=>$Weather{Sky}, 'WindDir'=>$Weather{WindDir}, 'Barometer'=>$Weather{Barometer} ); # create object my $wxml = new XML::Simple (NoAttr=>1, RootName=>'weather'); # convert Perl array ref into XML document my $wdata = $wxml->XMLout(\%arr); # access XML data print XMLFILE $wdata; close XMLFILE; open (jsonFILE, '>/var/www/html/weatherj.xml'); my $json_obj = new JSON; print jsonFILE $json_obj->pretty->encode(\%arr); close jsonFILE; } --------------------------------------------------- # more /var/www/html/weather.xml <weather></weather> # more /var/www/html/weatherj.xml { "Time" : " 1:33 PM", "ForCastLow" : "51", "WindDir" : "6", "ForCastHigh" : "79", "Barometer" : "29.95", "ForCast" : "Sunny, with a high near 79. Calm wind becoming north northwest around 6 mph in the afternoon. ", "MinTemp" : "46", "TempOutside" : "83", "WindSpeed" : "0", "Date" : "Mon, Sep 17", "TempGarage" : "80", "SkyCondition" : "sky clear ", "TempIn1" : "75", "Radiance" : "90", "MaxTemp" : "87", "RelHumid1" : "44" } |