<?php

/**
 * Simple XML Parser
 * 
 * @author     vinadelmar <vinadelmar@users.sourceforge.net>
 * @package    Core
 * @subpackage Parser
 */
class XMLParser {
	/**#@+
	 * @access private
	 */
	/**
	 * @var string XML
	 */
	var $xmlString;
	
	/**
	 * @var array holds info about tags
	 */
	var $tags;
	
	/**
	 * @var array holds data between tags
	 */
	var $values;
	
	/**
	 * Class Constructor
	 *
	 * @param string $xmlFile path to XML file
	 */
	function XMLParser($xmlFile) {
		if (($string = file_get_contents($xmlFile)) === false) {
			$this->xmlString = '';
		}
		else {
			$this->xmlString = trim($string);
		}
	}
	
	/**
	 * Parse XML File
	 *
	 * @return boolean
	 */
	function parse() {
		if (!$this->xmlString) {
			return false;
		}
		
		$p = xml_parser_create('UTF-8');
		xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
		
		$parsed = xml_parse_into_struct($p, $this->xmlString, $this->values, $this->tags);
		
		xml_parser_free($p);
		
		if (!$parsed) {
			return false;
		}
		
		return true;
	}
	
	/**
	 * Gets XML
	 *
	 * @return string XML
	 */
	function getXml() {
		return $this->xmlString;
	}
	
	/**
	 * @return array
	 */
	function getTags() {
		return $this->tags;
	}
	
	/**
	 * @return array
	 */
	function getValues() {
		return $this->values;
	}
	
	/**
	 * @return integer
	 */
	function getNumValues() {
		return count($this->values);
	}
	
	/**
	 * @return integer
	 */
	function getNumTags() {
		return count($this->tags);
	}
}

?>