Location: PHPKode > projects > FarODP > farodp/includes/xml/XMLObject.php
<?php

class XMLObject {
	var $data = '';
	var $element = '';
	var $level;
	var $stack;
	
	function XMLObject() {
		$this->level = 0;
		$this->stack = array();
	}

	function openElement($level, $element, $params = array()) {
	    $this->level++;
	    $this->stack[$this->level] = $element;
	    $this->element = $element;
	    $param = '';
	    foreach ($params as $k=>$v) {
			$param .= ' ' . htmlspecialchars($k) . '="' . htmlspecialchars($v) . '"';
	    }
	    $this->data .= '<' . htmlspecialchars($element) . $param . '>'."\r\n";
	}
	
	function closeElement() {
	    if ($this->level === 0) {
	        trigger_error('level below zero');
	        return;
	    }
	    $this->data .= '</' . htmlspecialchars($this->stack[$this->level]) . '>'."\r\n";
	    $this->level--;
	}
	
	function addElement($element, $params = array()) {
	    $this->lastClosed = true;
	    $param = '';
	    foreach ($params as $k=>$v) {
			$param .= ' ' . htmlspecialchars($k) . '="' . htmlspecialchars($v) . '"';
	    }
	    $this->data .= '<' . htmlspecialchars($element) . $param . '/>'."\r\n";
	}
	
	function addText($str) {
	    $this->data .= htmlspecialchars($str);
	}
	
	function close($i) {
	    while ($i > 0) {
	        $this->closeElement();
	        $i--;
	    }
	}
	
	function toLevel($level) {
	    $diff = $this->level - $level;
	    $this->close($diff);
	}
	
	function getXML() {
	    $this->close($this->level);
	    return $this->data;
	}
}
?>
Return current item: FarODP