Jump to content

Recommended Posts

Hi all,

 

I'm enjoying learning myself, but want to make sure my big picture steps are efficient for this project:

 

I want to make a running http://sparkline.org/ of "good" weather vs. "bad" weather in my area. This will look at a federal XML file once a day with a cron job, parse the data, store it to my own database, then query the previous 10 entires in the DB to create the sparkline. Is this a reasonable way to execute this project?

 

Also, I'm at the point where I can import the xml stream, but am not sure the best way to get at it. Xpath queries? Can't some function turn it into an array? I'm not so good at these things, so any hints would be great. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/
Share on other sites

ok, so here is the code I have:

Blah

<?php

// displays all the file nodes
if(!$xml=simplexml_load_file('http://www.weather.gov/xml/current_obs/KBOS.xml')){
    trigger_error('Error reading XML file',E_USER_ERROR);
}

$weather = $xml->current_observation->weather;

echo $weather;

?>

 

When I load up the page (not locally, for what it's worth) it only displays "Blah", not even the error specified. Can I not use the simplexml_load_file function on remote files?

 

I know fopen works remotely... but that's not what I really want to do. Suggestions?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784131
Share on other sites

current_observation is the root element, so you don't need to navigate to it (aka $xml is already at that node). So it would just be:

 

Blah

<?php

// displays all the file nodes
if(!$xml=simplexml_load_file('http://www.weather.gov/xml/current_obs/KBOS.xml')){
    trigger_error('Error reading XML file',E_USER_ERROR);
}
$weather = $xml->weather;

echo $weather;

?>

 

just do a print_r($xml) to see all the info

Link to comment
https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784145
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.