Location: PHPKode > projects > ChurchCMS > churchcms/lib/parser.inc.php
 *                                            ChurchCMS
 * Copyright (C) 2005 jsvoyager
 * Developers & Contributors:
 * jsvoyager					hide@address.com
 * 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.
 * (license.txt)
  This parser takes module xml files and creates an array about them.
  The array is formatted as such:
  			['name'] 		: Name of module
  			['version']		: Version of module
  			['desc']			: Description of module
  								['name']			: Name of that table
  													['disp']		:(true|false) Should this field be displayed by an external formater
  													['dbname']	: Name of field in database
  													['dispname']: Name to be displayed to user
  													['desc']		: Description of field, to be displayed to user
  								['module']	: Name of module
  								['version']	: Version required
  								['inequ']	: (greater|equal) Describes the inequality to the version number (ie, >=2.0)
  							['file']			: File to be included on the home index (/index.php)
  							['possition']	: (main|side) Location: Sidebar or main section?


function ParseMoudleXML($file){
	global $module;
	// Define the parser, set handelers
	$simpleparser = xml_parser_create();
	xml_set_element_handler($simpleparser, "startElement", "endElement");
	xml_set_character_data_handler($simpleparser, "characterData");

	// Open the XML file for reading
	if (!($fp = fopen($file, "r"))) {
		die("could not open XML input");

	// Parse it
	while ($data = fread($fp, filesize($file))) {
	if (!xml_parse($simpleparser, $data, feof($fp))) {

	// Free memory
	return $module;

// Call this at the beginning of every element
function startElement($parser, $name, $attrs) {
	global $openelements, $module;
	$openelements[] = $name;
	//Figure out what do with the attrs by name of element
	if ($name == "module"){
		$module['name'] = $attrs['name'];
		$module['version'] = $attrs['version']

// Call this at the end of every element
function endElement($parser, $name) {
	global $openelements, $module;
	print tabs(count($openelements)) . "}\n";

// Call this whenever there is character data
function characterData($parser, $value) {
	global $openelements, $module;
	print tabs(count($openelements)) . trim($value) . "\n";

Return current item: ChurchCMS