3 * XMPPHP: The PHP XMPP Library
4 * Copyright (C) 2008 Nathanael C. Fritz
5 * This file is part of SleekXMPP.
7 * XMPPHP is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * XMPPHP is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XMPPHP; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
24 * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
25 * @author Michael Garvin <JID: gar@netflint.net>
26 * @copyright 2008 Nathanael C. Fritz
34 * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
35 * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
36 * @author Michael Garvin <JID: gar@netflint.net>
37 * @copyright 2008 Nathanael C. Fritz
60 public $attrs = array();
67 public $subs = array();
84 public function __construct($name, $ns = '', $attrs = array(), $data = '') {
85 $this->name = strtolower($name);
87 if(is_array($attrs) && count($attrs)) {
88 foreach($attrs as $key => $value) {
89 $this->attrs[strtolower($key)] = $value;
96 * Dump this XML Object to output.
98 * @param integer $depth
100 public function printObj($depth = 0) {
101 print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
103 foreach($this->subs as $sub) {
104 $sub->printObj($depth + 1);
109 * Return this XML Object in xml notation
113 public function toString($str = '') {
114 $str .= "<{$this->name} xmlns='{$this->ns}' ";
115 foreach($this->attrs as $key => $value) {
116 if($key != 'xmlns') {
117 $value = htmlspecialchars($value);
118 $str .= "$key='$value' ";
122 foreach($this->subs as $sub) {
123 $str .= $sub->toString();
125 $body = htmlspecialchars($this->data);
126 $str .= "$body</{$this->name}>";
131 * Has this XML Object the given sub?
133 * @param string $name
136 public function hasSub($name, $ns = null) {
137 foreach($this->subs as $sub) {
138 if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true;
146 * @param string $name
147 * @param string $attrs
150 public function sub($name, $attrs = null, $ns = null) {
151 #TODO attrs is ignored
152 foreach($this->subs as $sub) {
153 if($sub->name == $name and ($ns == null or $sub->ns == $ns)) {