xmpphp/xmlobj.php
fritzy aba0b3f7e7 * fixes
git-svn-id: svn://netflint.net/xmpphp@14 ef36c318-a008-4979-b6e8-6b496270793b
2008-04-04 07:19:17 +00:00

79 lines
1.9 KiB
PHP

<?php
/*
XMPPHP: The PHP XMPP Library
Copyright (C) 2008 Nathanael C. Fritz
This file is part of SleekXMPP.
XMPPHP is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
XMPPHP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XMPPHP; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class XMLObj {
var $name;
var $ns;
var $attrs = array();
var $subs = array();
var $data = '';
function XMLObj($name, $ns='', $attrs=array(), $data='') {
$this->name = strtolower($name);
$this->ns = $ns;
if(is_array($attrs)) {
foreach($attrs as $key => $value) {
$this->attrs[strtolower($key)] = $value;
}
}
$this->data = $data;
}
function printobj($depth=0) {
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
print "\n";
foreach($this->subs as $sub) {
$sub->printobj($depth + 1);
}
}
function tostring($str='') {
$str .= "<{$this->name} xmlns='{$this->ns}' ";
foreach($this->attrs as $key => $value) {
if($key != 'xmlns') {
$value = htmlentities($value);
$str .= "$key='$value' ";
}
}
$str .= ">";
foreach($this->subs as $sub) {
$str .= $sub->tostring();
}
$body = htmlentities($this->data);
$str .= "$body</{$this->name}>";
return $str;
}
function hassub($name) {
foreach($this->subs as $sub) {
if($sub->name == $name) return True;
}
return False;
}
function sub($name, $attrs=Null, $ns=Null) {
foreach($this->subs as $sub) {
if($sub->name == $name) return $sub;
}
}
}
?>