private function parse_xml($xData) { libxml_use_internal_errors(true); try { $weather = new SimpleXMLElement($xData); } catch (Exception $err) { // Set current exception message last getMessage() throw new Exception($err->getMessage()); } // Select the current_conditions node ($cNode) if (!isset($weather->weather[0]->current_conditions)) { throw new Exception("Unable to find data for the specified location"); } $cNode = $weather->weather[0]->current_conditions; // ========= Set up our current conditions array ==================== // Tempreature - temp_f Fahrenheit, temp_c celsius - set as floats. $this->_wData['current']['temp_f'] = $cNode->temp_f->attributes()->data; $this->_wData['current']['temp_c'] = weather::to_celsius($this->_wData['current']['temp_f']); // Condition $this->_wData['current']['condition'] = $cNode->condition->attributes()->data; // Condition Icon - icon url is not absolute, append google.com $this->_wData['current']['icon'] = "http://www.google.com" . $cNode->icon->attributes()->data; // Wind Condition $this->_wData['current']['wind'] = $cNode->wind_condition->attributes()->data; // ============= Set up our forecast array ============= $fNode = $weather->weather[0]->forecast_conditions; // Iterate through each day of the week and create an assoc array. foreach ($fNode as $forecast) { // Get the day. $day = (string) $forecast->day_of_week->attributes()->data; // Insert an array of info for that day $this->_wData['forecast'][$day] = array("day" => $day, "high" => $forecast->high->attributes()->data, "low" => $forecast->low->attributes()->data, "icon" => "http://www.google.com" . $forecast->icon->attributes()->data, "condition" => $forecast->condition->attributes()->data); } //foreach ($fNode as $forecast) // Let the class know wData is ready for use. }