This program 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. This program 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 this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ class XMLNode { var $m_name; // The node name var $m_attributes; // Array of attributes var $m_value; // The node value var $m_children; // Array of nodes function XMLNode($name, $attributes = array(), $value = '') { $this->m_name = $name; $this->m_attributes = $attributes; $this->m_children = array(); $this->setValue($value); } function addChild($xmlNode) { $this->m_children[] = $xmlNode; } function setValue($value) { $this->m_value = $value; } function generate($xmlVersion = '1.0', $encoding = 'utf-8') { // XML header $res = ''; // Content $res = $this->toString(); return $res; } function toString() { // Open the tag $res = '<' . $this->m_name; // Write the attributes if (!empty($this->m_attributes)) { foreach ($this->m_attributes as $name => $value) $res .= ' ' . $name . '="' . $value . '"'; } // Write the node content if (empty($this->m_children) && $this->m_value == '') { // No children or attributes $res .= ' />'; } else { $res .= '>'; // Write the children nodes foreach ($this->m_children as $child) $res .= $child->toString(); // Write the node value if ($this->m_value != '') $res .= $this->m_value; // Close the tag $res .= 'm_name . '>'; } return $res; } } ?>