note 57736 added to ref.xml
| From: | m dot quinton at gmail dot com | Date: | Wed, 12 Oct 2005 19:32:09 +0000 |
| Subject: | note 57736 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96910@lists.php.net to get a copy of this message | ||
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();
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57736
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57736&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57736&report=yes
Search -- http://master.php.net/manage/user-notes.php