yuckysocks Posted March 13, 2009 Share Posted March 13, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/ Share on other sites More sharing options...
rhodesa Posted March 13, 2009 Share Posted March 13, 2009 I would use SimpleXML to parse the XML file. It allows you to effortlessly access and loop over the elements. Quote Link to comment https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784015 Share on other sites More sharing options...
yuckysocks Posted March 13, 2009 Author Share Posted March 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784131 Share on other sites More sharing options...
rhodesa Posted March 13, 2009 Share Posted March 13, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784145 Share on other sites More sharing options...
yuckysocks Posted March 13, 2009 Author Share Posted March 13, 2009 That's all I needed to hear. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/149293-solved-xml-parsing/#findComment-784147 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.