All pastes #919814 Raw Edit

parse xml problem

public php v1 · immutable
#919814 ·published 2008-02-27 00:24 UTC
rendered paste body
<?phperror_reporting(E_ALL);//session_start();// Include filesinclude_once("../../../settings/verifyauth.php");include_once("../../../settings/dbase_login.php");include_once("config_dirpath.php");// Initialise all the redirect locations$back = $file_path . 'import.php';$continue = $file_path . 'import.php';// Trim post variables//$_SESSION['temp'] = 'test 123';/* ============================================SYSTEM MESSAGE STRINGS============================================ */$msgStandard = "<tr><td height=\"30\" colspan=\"2\" class=\"text-errormsg\"><b>ERROR! Please fill out the following fields:</b><br>";$msgEmailFormat = "<tr><td height=\"30\" colspan=\"2\" class=\"text-errormsg\"><b>ERROR! The following problems occured:</b><br>";$msgCustExist = "<tr><td height=\"30\" colspan=\"2\" class=\"text-errormsg\"><b>ERROR!</b><br>This Personnel already exists in the system. Please add another entry!</td></tr>";$msgTaskComplete = "<tr><td height=\"30\" colspan=\"2\" class=\"text-confirmmsg\"><b>TASK COMPLETE!</b></td></tr>";// Initialise all sessions	$XMLFileChk = (isset($_FILES['xmlfile']) && is_uploaded_file($_FILES['xmlfile']['tmp_name'])) ? true : false;// Arrays -  of required HTML field names and correspond error messages for each field name$htmlfields = array($XMLFileChk);$errfields = array('XML File');// this is the total number of required fields $numFields = count($htmlfields);//initiate value for first check//the first check is to ensure user fills in all required fields.$errorFound01=false;$msg01 = $msgStandard;for($i=0; $i<$numFields; $i++){	if ((!strlen($htmlfields[$i]) > 0) || ($htmlfields[$i] == ""))	{		$msg01 = $msg01 . $errfields[$i] . "<br>";		$errorFound01 = true;	}}if($errorFound01){	$_SESSION["errorMsg"] = $msg01 . "</font></td></tr>";	header("Location: $back");}// Initiate second checkelse {	//initiate value for second check	$errorFound02=false;	$msg02 = $msgEmailFormat;			/*	arrayChkFields = array();	$numChkFields = count($arrayChkFields);		for($j=0; $j<$numChkFields; $j++)	{		if(!ereg($arrayChkFields[$j][1], $arrayChkFields[$j][0]))		{			$errorFound02 = true;			$msg02 .= $arrayChkFields[$j][2];		}	}	*/		if($errorFound02)	{		$_SESSION['errorMsg'] = $msg02 . "</font></td></tr>";		header("Location: $back");	} 	else	{		// do stuff here		$xmlfile_data = '';		$xml_data = '';		$current_tag = '';				$listing = array();		$index = 0;				$fh = fopen($_FILES['xmlfile']['tmp_name'], "r") or die("Unable to open XML file");		/* Read data from file into a string buffer *///		while (!feof($fh)) {//			$xmlfile_data .= fread($fh, 4096);//		}						$parser = xml_parser_create();				/* Disable XML tag capitalisation (Case Folding) */		xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, FALSE);//		xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING, 'US-ASCII');//		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);				/* Define Callback functions for XML Parsing */		//xml_set_object($this->parser, &$this);		xml_set_element_handler ($parser, "xml_element_start", "xml_element_end");		xml_set_character_data_handler ($parser, "xml_data");				// read data from input and parse		while ($data = fread($fh, 4096)) {			if (!xml_parse($parser, $data, feof($fh))) {				die('Whoops');			}		}				/* Parse the XML response *///		xml_parse($parser, $xmlfile_data, TRUE);				/* Clean up after ourselves */		xml_parser_free ($parser);		fclose ($fh);				echo "Debug: ";		print_r($listing);		echo "<br>\n";					//unset();		$_SESSION['errorMsg'] = $msgTaskComplete;		header("Location: $continue");		}			}/* Call back Functions for the XML Parser */function xml_element_start ($parser, $tag, $attributes) {	global $current_tag;	global $in_listing, $listing, $index;		$tmp_array = array();		$current_tag = $tag;	switch(strtolower($tag)) {	case 'propertylist':		echo "Debug: Found propertyList start tag<br>\n";		break;	case 'residential':		echo "Debug: Found residential listing start tag<br>\n";		$in_listing = true;				$listing[$index] = array();		$listing[$index]['Classification'] = 'Property';		break;	case 'land':		echo "Debug: Found land listing start tag<br>\n";		$in_listing = true;				$listing[$index] = array();		$listing[$index]['Classification'] = 'Land';		break;	case 'images':		echo "Debug: Found image list<br>\n";		$listing[$index]['images'] = $tmp_array;		$listing[$index]['images'][0] = '';		echo "Debug: isset(\$listing[\$index]['images']) [".(isset($listing[$index]['images']) ? 'true' : 'false')."] is_array(\$listing[\$index]['images']) [".(is_array($listing[$index]['images'])  ? 'true' : 'false')."]<br>\n";				echo "Debug: ";		print_r($listing);		echo "<br>\n";				break;	case 'img':		echo "Debug: Found image - ";		print_r($attributes);		echo "<br>\n";		echo "Debug: ";		print_r($listing);		echo "<br>\n";				echo "Debug: isset(\$listing[\$index]['images']) [".(isset($listing[$index]['images']) ? 'true' : 'false')."] is_array(\$listing[\$index]['images']) [".(is_array($listing[$index]['images'])  ? 'true' : 'false')."]<br>\n";		$listing[$index]['images'][] = '';		break;	default:		echo "Setting \$listing[\$index][\$current_tag] to null (index is $index - current_tag is $current_tag)<br>\n";		$listing[$index][$current_tag] = '';		break;	}}function xml_element_end ($parser, $tag) {	global $current_tag;	global $in_listing, $listing, $index;			switch(strtolower($tag)) {	case 'propertylist':		echo "Debug: Found propertyList end tag<br>\n";		break;	case 'residential':		echo "Debug: Found residential listing end tag<br>\n";		$in_listing = false;		$index++;		break;	case 'land':		echo "Debug: Found land listing end tag<br>\n";		$in_listing = false;		$index++;		break;	default:		break;	}			$current_tag = "";}function xml_data ($parser, $cdata) {	global $xml_data, $current_tag;		global $in_listing, $listing, $index;	// we're only interested in data thats inside a property listing	if($in_listing) {		if($current_tag)			$listing[$index][$current_tag] .= $cdata;		/*		else			echo "Debug: (In listing) - current tag is null<br>\n";		*/	}}?>