note 57736 deleted from ref.xml by bjori

From: Date: Mon, 09 Oct 2006 11:12:08 +0000
Subject: note 57736 deleted from ref.xml by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118279@lists.php.net to get a copy of this message
Note Submitter: m dot quinton at gmail dot com ---- an example of using "monte" class for Klm XLM file from Google Earth. KlmObject can be reused because it uses xmlParser output as input. <?php error_reporting(E_ALL); $p =& new xmlParser(); $p->parse('your_file.kml'); $tree = $p->GetNodeByPath('KML/FOLDER'); $folder = new KlmFolder($tree); echo "type : " . $folder->type() . "\n"; echo "name : " . $folder->name() . "\n"; $placemarks = $folder->get_placemarks(); foreach($placemarks as $place){ echo $place->toText() . "\n"; } class KlmObject { var $tree; function type(){ return $this->tree['name']; } function name(){ $node = $this->child_by_name('NAME'); return $node['content']; } function &childs(){ return $this->tree['child']; } function child_by_name($name){ foreach($this->childs() as $key=>$val){ $val = &$this->tree['child'][$key]; if($val['name'] == $name) return $val; } return false; } } class KlmFolder extends KlmObject{ function KlmFolder(&$tree){ $this->tree = &$tree; } function get_placemarks(){ $placemarks = array(); foreach($this->childs() as $val){ echo "{$val['name']}\n"; if($val['name'] == 'FOLDER'){ $subfolder = &new KlmFolder($val); $placemarks = array_merge($placemarks, $subfolder->get_placemarks()); } if($val['name'] == 'PLACEMARK'){ $placemarks[] = &new KlmPlacemark($val); } } return $placemarks; } } class KlmPlaceMark extends KlmObject{ var $tree; function KlmPlacemark($tree){ $this->tree = &$tree; $name = $this->name(); print_r($tree); } function longitude(){ return $this->tree['child'][1]['child'][0]['content']; } function latitude(){ return $this->tree['child'][1]['child'][1]['content']; } function toText(){ return $this->name() . ' : ' . $this-> longitude() . ' - ' . $this-> latitude(); } } ?>

« previous php.notes (#118279) next »