Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/jabber/XMPP/XMLObj.php
Go to the documentation of this file.
00001 <?php 
00040 class XMPPHP_XMLObj {
00046         public $name;
00047         
00053         public $ns;
00054         
00060         public $attrs = array();
00061         
00067         public $subs = array();
00068         
00074         public $data = '';
00075 
00084         public function __construct($name, $ns = '', $attrs = array(), $data = '') {
00085                 $this->name = strtolower($name);
00086                 $this->ns   = $ns;
00087                 if(is_array($attrs) && count($attrs)) {
00088                         foreach($attrs as $key => $value) {
00089                                 $this->attrs[strtolower($key)] = $value;
00090                         }
00091                 }
00092                 $this->data = $data;
00093         }
00094 
00100         public function printObj($depth = 0) {
00101                 print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
00102                 print "\n";
00103                 foreach($this->subs as $sub) {
00104                         $sub->printObj($depth + 1);
00105                 }
00106         }
00107 
00113         public function toString($str = '') {
00114                 $str .= "<{$this->name} xmlns='{$this->ns}' ";
00115                 foreach($this->attrs as $key => $value) {
00116                         if($key != 'xmlns') {
00117                                 $value = htmlspecialchars($value);
00118                                 $str .= "$key='$value' ";
00119                         }
00120                 }
00121                 $str .= ">";
00122                 foreach($this->subs as $sub) {
00123                         $str .= $sub->toString();
00124                 }
00125                 $body = htmlspecialchars($this->data);
00126                 $str .= "$body</{$this->name}>";
00127                 return $str;
00128         }
00129 
00136         public function hasSub($name, $ns = null) {
00137                 foreach($this->subs as $sub) {
00138                         if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true;
00139                 }
00140                 return false;
00141         }
00142 
00150         public function sub($name, $attrs = null, $ns = null) {
00151                 #TODO attrs is ignored
00152                 foreach($this->subs as $sub) {
00153                         if($sub->name == $name and ($ns == null or $sub->ns == $ns)) {
00154                                 return $sub;
00155                         }
00156                 }
00157         }
00158 }
 All Data Structures Namespaces Files Functions Variables Enumerations