Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Parsing NWS Public Alerts in CAP/ATOM

by johnfl68 (Scribe)
on Jul 23, 2012 at 03:49 UTC ( [id://983103]=note: print w/replies, xml ) Need Help??


in reply to Parsing NWS Public Alerts in CAP/ATOM

Ok

So here is what I have:

#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use XML::Simple; # use XML::LibXML; use POSIX qw(strftime); no warnings 'uninitialized'; use Data::Dumper; my $data_dir = "/weatherdata"; my $current_file = 'SDC095.xml'; my $current = XMLin($current_file); # These seem to work if there is no active alert # my $warntitle = $current->{'entry'}->{'title'}; # my $warnlink = $current->{'entry'}->{'id'}; # my $warntext = $current->{'entry'}->{'summary'}; # These work if I already know the full URL for the alert my $warntitle = $current->{'entry'}->{'http://alerts.weather.gov/cap/w +wacapget.php?x=SD124CB88C681C.SpecialWeatherStatement.124CB88C9184SD. +UNRSPSUNR.046ee1fda521a403079118865edf9ad4'}->{'title'}; my $warnlink = $current->{'entry'}->{'http://alerts.weather.gov/cap/ww +acapget.php?x=SD124CB88C681C.SpecialWeatherStatement.124CB88C9184SD.U +NRSPSUNR.046ee1fda521a403079118865edf9ad4'}->{'id'}; my $warntext = $current->{'entry'}->{'http://alerts.weather.gov/cap/ww +acapget.php?x=SD124CB88C681C.SpecialWeatherStatement.124CB88C9184SD.U +NRSPSUNR.046ee1fda521a403079118865edf9ad4'}->{'summary'}; print "$warntitle\n"; print "$warnlink\n"; print "$warntext\n"; # print output # print Dumper($current);

And here is the XML file:

https://dl.dropbox.com/u/2859483/SDC095.xml

It wont let me post it as code in this message

So, usually if there is no warnings in the area, I get the data ok, but in this case, instead of the second tier being 'title' 'id' and 'summary' those are being pushed to the third tier, and the second tier key is now 'http://alerts.weather.gov/cap/wwacapget.php?x=SD124CB88C681C.SpecialWeatherStatement.124CB88C9184SD.UNRSPSUNR.046ee1fda521a403079118865edf9ad4' and since I do not know that in advance, it's hard to get results that way.

John

Replies are listed 'Best First'.
Re^2: Parsing NWS Public Alerts in CAP/ATOM
by GrandFather (Saint) on Jul 23, 2012 at 04:06 UTC

    Try stripping the problematic XML down to something that shows the issue, but is small enough to post. Also strip everything out of your sample code that's not related to the issue. Doing this has two benefits: the less work we have to do to help you the more likely you are to get help, and it is fairly likely that in the process of tidying up for posting that you will find the problem yourself.

    Note that XML::Simple is not really a general purpose XML parser and often comes unstuck for "interesting" XML. You may be better to use XML::Twig or one of the other "less simple" XML parsers.

    True laziness is hard work
Re^2: Parsing NWS Public Alerts in CAP/ATOM
by Anonymous Monk on Jul 23, 2012 at 06:32 UTC
Re^2: Parsing NWS Public Alerts in CAP/ATOM
by johnfl68 (Scribe) on Jul 25, 2012 at 06:48 UTC

    Well XML::Feed has way too many dependencies that are not on my server (shared server), so I didn't install because it needed too many other mods. XML::Twig installed fine, but wow, it does way too much (I'm sure that is great for more complex things), and I am having a hard time trying to figure out how to even parse a simpler current weather conditions xml file with out it coming up with errors like "Use of uninitialized value $temp_F in concatenation (.) or string at parsetest.pl" And it is getting really frustrating. I was have better luck with XML::Simple until I started trying to read the CAP Alerts. :(

    John

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://983103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-19 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found