Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Parsing NDFD with XML::Simple

by johnfl68 (Beadle)
on Jul 14, 2012 at 00:24 UTC ( #981744=perlquestion: print w/replies, xml ) Need Help??
johnfl68 has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, and thank you for your time.

I'm trying to work with some data from the US National Weather Service, using the NDFD SOAP server.

I am able to get the data from the server fine, and can read the XML file with XML::Simple, and have done a "Dummper" of the output (, so I think so far I am going in the right direction. But in trying several different XML::Simple examples for getting the data out of the data string for the XML file, I get responses like "HASH(0x4f01dc0)" or with another means I got "Unquoted string "conditions" may clash with future reserved word at line 28." and the same for the other defined items in the XML.

I am sure I am not the only one that has tried to get data from the NDFD, I have run across a few threads in searching google that are here, but using the search here keeps saying that there are none.

If anyone knows of some good working examples that I could look at, it would be appreciated.


Replies are listed 'Best First'.
Re: Parsing NDFD with XML::Simple
by Anonymous Monk on Jul 14, 2012 at 08:59 UTC
Re: Parsing NDFD with XML::Simple
by frozenwithjoy (Priest) on Jul 14, 2012 at 01:48 UTC
    Can you please post the relevant code that isn't working for you?
Re: Parsing NDFD with XML::Simple
by aitap (Curate) on Jul 14, 2012 at 08:32 UTC
    Can you please show an exmaple of XML file? It would be easier to write and test the code to parse it.
    Sorry if my advice was wrong.
Re: Parsing NDFD with XML::Simple
by johnfl68 (Beadle) on Jul 14, 2012 at 23:30 UTC

    Ok - actually, I separated things back out, and it seems to be a SOAP problem to begin with.

    The script only makes the request, and then saves it to an XML file.

    #!/usr/bin/perl use SOAP::Lite; use DateTime; my $lattitude = 28.3887; my $longitude = -81.4773; my $numDays = 6; # up to 7 days my $format = '12 hourly'; # '12 hourly' or '24 hourly' my $xml_file = 'forecast.xml'; my $dt = DateTime->now; $dt->set_time_zone('local'); my $startDate = $dt->strftime('%Y-%m-%d%z'); $startDate =~ s/(\d{2})(\d{2})$/$1:$2/; # final format: "2005-01-24-06 +:00" my $serviceURI = ''; my $method = 'NDFDgenByDay'; my $endpoint = "$serviceURI/SOAP_server/ndfdXMLserver.php"; my $soapAction = "$serviceURI/DWMLgen/wsdl/ndfdXML.wsdl#$method"; my $weather = SOAP::Lite->new(uri => $soapAction, proxy => $endpoint); my $response = $weather->call( SOAP::Data->name($method) => SOAP::Data->type(decimal => $lattitude)->name('latitude'), => SOAP::Data->type(decimal => $longitude)->name('longitude'), => SOAP::Data->type(date => $startDate)->name('startDate'), => SOAP::Data->type(integer => $numDays )->name('numDays'), => SOAP::Data->type(string => $format )->name('format') ); if ($response->fault) { printf "A fault (%s) occurred: %s\n", $response->faultcode, $response->faultstring; } else { open(OUT, ">$xml_file"); print OUT $response->result; }

    It is giving the following error:

    not well-formed (invalid token) at line 77, column 13, byte 3304 at /usr/lib/perl5/vendor_perl/5.12.2/i686-linux/XML/ line 187

    Here is the Trace if it is any help:

    I verified with the original author that the script is currently working on his site right now.

    So I am not sure where to go next with getting this to work.

    Thanks for any insight!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://981744]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-07-18 05:19 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (383 votes). Check out past polls.