tanveer Posted June 8, 2011 Share Posted June 8, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/ Share on other sites More sharing options...
fugix Posted June 8, 2011 Share Posted June 8, 2011 what error(s) are you receiving? Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1227118 Share on other sites More sharing options...
tanveer Posted June 8, 2011 Author Share Posted June 8, 2011 This page contains the following errors: error on line 80 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error. Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1227157 Share on other sites More sharing options...
tanveer Posted June 14, 2011 Author Share Posted June 14, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1229372 Share on other sites More sharing options...
fugix Posted June 14, 2011 Share Posted June 14, 2011 cqan you can the exact location where the error is being triggered, line 80 Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1229473 Share on other sites More sharing options...
tanveer Posted June 14, 2011 Author Share Posted June 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1229498 Share on other sites More sharing options...
fugix Posted June 14, 2011 Share Posted June 14, 2011 to my knowledge, you cannot output both xml and html within the same http response. The client does not know what to do with it. You can output one or the other, will need to think of a workaround Quote Link to comment https://forums.phpfreaks.com/topic/238809-error-showing-confirmation-after-generating-an-xml-file/#findComment-1229503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.