Jump to content

Error showing confirmation after generating an XML file


tanveer

Recommended Posts

Hi,

 

I am creating an XML file from the mysql database and it's creating fine. But after creating it and writing it to a file I just want to show the output as "File creation is successful" that sort of message. But it gives me error if I call the function to show that message.

Below is the code:

public function generateXML($resultID){


	header("Content-type: text/xml");
	$xml_output  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	$xml_output .= "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\">\n";
        $xml_output .= "<graph edgedefault=\"directed\">\n";

	$xml_output .= "<key id=\"name\" for=\"node\" attr.name=\"sender\" attr.type=\"string\"/>\n";

	for($x = 1 ; $x < mysql_num_rows($resultID) ; $x++){
		$row = mysql_fetch_assoc($resultID);
		$xml_output .= "\t<node id=\"$x\">\n";
		$xml_output .= "\t\t<data key=\"name\">" . $row['sender'] . "</data>\n";
		$xml_output .= "\t</node>\n";
	}

	$xml_output .= "</graph>\n";
	$xml_output .= "</graphml>\n";

		return $xml_output; 	


}

public function createXMLFile ($xml_output){

	// print $xml_output;

	$file_handle = fopen('/tmp/socialNetwork.xml','w');

	fwrite($file_handle,$xml_output);

	fclose($file_handle);

}
// It gives an error if I call this function for showing the file creation status.
public function showMessage (){

                              echo "<H1> File Successfully Created </H1>";

}

}

$snxml 	     = new SocialNetworkXML;
$holdResult   = $snxml->setQuery("select distinct sender from message1");
$xml_output = $snxml->generateXML($holdResult);

$snxml->createXMLFile($xml_output);
        $snxml->showMessage(); 
?>

Anyone has any idea why this is happening ? It's giving error if I want to show any message after creating the file.


class SocialNetXML extends SystemConfig {

public $sqlQuery	= "";
public $resultID	= "";

public function setQuery($query){

	$dbConnect = new DBConnect();
	$dbConnect->Connection("localhost", "dbname", "user", "");
	$resultID = mysql_query($query) or die("Data not found.");

	return $resultID;


}

public function generateXML($empIDList, $relationList){

	header("Content-type: text/xml");
	$xml_output  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	$xml_output .= "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\">\n";
        $xml_output .= "<graph edgedefault=\"directed\">\n";

	$xml_output .= "<key id=\"name\" for=\"node\" attr.name=\"sender\" attr.type=\"string\"/>\n";

	for($x = 1 ; $x <= mysql_num_rows($empIDList) ; $x++){
		$row = mysql_fetch_assoc($empIDList);
		$xml_output .= "\t<node id=\"$x\">\n";
		$xml_output .= "\t\t<data key=\"name\">" . $row['emp_addr'] . "</data>\n";
		$xml_output .= "\t</node>\n";
	}

	for($x = 1 ; $x <= mysql_num_rows($relationList) ; $x++){
		$row = mysql_fetch_array($relationList);
		$xml_output .= "\t<edge source=\"" . $row[0] . "\" target=\"" . $row[1] . "\"></edge>\n";
	}

	$xml_output .= "</graph>\n";
	$xml_output .= "</graphml>\n";

		return $xml_output; 	


}

public function createXMLFile ($xml_output){

	print $xml_output;

	$file_handle = fopen('/tmp/authorNetwork.xml','w');

	fwrite($file_handle,$xml_output);

	fclose($file_handle);

}

public function confirmationMsg(){
		print "<h1> XML File Has Been Successfully Created </h1> <br />
		     	    <h2> XML File Location: /tmp  </h2>
			      ";	
}

}

$enxml 			 	 = new SocialNetworkXML;
// Finding the Author's who sent mail.
//$empIDList 		 = $enxml->setQuery ("SELECT emp_name FROM emplist WHERE emp_name IS NOT NULL");
$empIDList 			 = $enxml->setQuery (" SELECT emp_addr FROM emplist ");
// Finding the Author's recipients whom they sent mail to generate the XML 
$relationList			 = $enxml->setQuery ("SELECT emp_id, receiver_id FROM message, rcptinfo WHERE message.mail_id = rcptinfo.mail_id");

$xml_output = $enxml->generateXML($empIDList, $relationList );

$enxml->createXMLFile($xml_output);

$enxml->confirmationMsg();

?>

hi thanks..

Yes thats the reason I was trying to know .. at line 80 is that function to show the message that XML file created successfully. Before that I am also closing the file handler but it's thinking it as a continuation of creating that xml file. Thats the problem actually.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.