beboo002 Posted June 9, 2008 Share Posted June 9, 2008 Hello freaks Cannot Write XML File using PHP/MySQL. I got some error Warning: domnode::append_child() expects parameter 1 to be object, null given in C:\wamp\www\xml\sitemap3.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\xml\sitemap3.php:9) in C:\wamp\www\xml\sitemap3.php on line 30 Fatal error: Call to a member function append_child() on a non-object in C:\wamp\www\xml\sitemap3.php on line 36 my code is <?php $username="root"; $password=""; $database="linksubmission"; // Start XML file, create parent node $doc = domxml_new_doc("1.0"); $node = $doc->create_element("Category"); $parnode = $doc->append_child($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM tbl_cat "; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("Category"); $newnode = $parnode->append_child($node); $newnode->set_attribute("Sub Cat Id", $row['sub_cat_id']); $newnode->set_attribute("Cat Name", $row['cat_name']); } $xmlfile = $doc->dump_mem(jgj); echo $xmlfile; ?> I am not understanding how can i remove this error currently i am using php5.2.3 Thanks Beboo Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/ Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 as far as line 9 and 36 error: i'd echo out and find what the value is before passing it Warning: Cannot modify header information Clear any whitespace in your closing ?> tag currently its like this: $xmlfile = $doc->dump_mem(jgj); echo $xmlfile; ?> needs to be: $xmlfile = $doc->dump_mem(jgj); echo $xmlfile; ?> Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561098 Share on other sites More sharing options...
beboo002 Posted June 9, 2008 Author Share Posted June 9, 2008 Thanks for reply nothing happened. Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561105 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 to be on the safe side just put your header right after <?php make sure theres nothing before <?php like whitespace or html tags Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561114 Share on other sites More sharing options...
beboo002 Posted June 9, 2008 Author Share Posted June 9, 2008 replace header after php then error is change now showing error <b>Warning</b>: domnode::append_child() expects parameter 1 to be object, null given in <b>C:\wamp\www\xml\sitemap3.php</b> on line <b>10</b><br /> ^ Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561121 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 try this it should echo an object $doc = domxml_new_doc("1.0"); $node = $doc->create_element("Category"); var_dump($node); $parnode = $doc->append_child($node); Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561175 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 if it isn't an object-try this <?php $doc = domxml_new_doc("1.0"); $node = $doc->create_element("Category"); $node->set_attribute("align", "left"); $parnode = $doc->append_child($node); ?> Link to comment https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/#findComment-561182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.