Source for file TeraWurflXMLParser_SimpleXML.php
Documentation is available at TeraWurflXMLParser_SimpleXML.php
* Tera_WURFL - PHP MySQL driven WURFL
* Tera-WURFL was written by Steve Kamerman, and is based on the
* Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
* This version uses a MySQL database to store the entire WURFL file, multiple patch
* files, and a persistent caching mechanism to provide extreme performance increases.
* @package TeraWurflXMLParser
* @author Steve Kamerman <stevekamerman AT gmail.com>
* @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
* @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
* Loads the wurfl.xml file using SimpleXML
* @package TeraWurflXMLParser
throw new Exception("Cannot load SimpleXML");
public function open($filename,$file_type){
// Use advanced logging from libXML
//TODO: Figure out why LibXML doesn't properly report "out of memory" errors
// when "libxml_use_internal_errors(true);". The errors are accounted
// for, but their ::message property is null.
//libxml_use_internal_errors(true);
foreach ($errors as $error) {
$this->errors[] = "$type: " . trim($error->message);
$this->errors[] = "Error: cannot parse XML file: $filename.";
throw new Exception("SimpleXML reported the following errors:\n". implode("\n",$this->errors));
public function process(Array &$destination){
$this->devices = & $destination;
if($this->file_type == self::$TYPE_WURFL && isset ($this->xml->version)){
$before_errors = count($this->errors);
$id = (string) $device['id'];
$this->devices[$id] = array('id'=> $id);
if(isset ($device['fall_back'])) $this->devices[$id]['fall_back'] = (string) $device['fall_back'];
if(isset ($device['actual_device_root'])){
$this->devices[$id]['actual_device_root'] = (string) $device['actual_device_root'];
$this->devices[$id]['actual_device_root'] = ($this->devices[$id]['actual_device_root'])? 1: 0;
foreach($device->group as $group){
$groupname = (string) $group['id'];
if($filtering && $this->enabled($groupname)){
foreach($group->capability as $cap){
$capname = (string) $cap['name'];
if(!$filtering || ($filtering && $includegroup) || ($filtering && !$includegroup && $this->enabled($capname))){
$groupdata[$capname]= $this->cleanValue((string) $cap['value']);
if(count($groupdata) > 0){
$this->devices[$id][$groupname] = $groupdata;
|