seco Posted January 4, 2008 Share Posted January 4, 2008 Hi i make xml structure using DOMdocument successfully and when i write echo $dom->saveXML($root); it prints out the xml structure successfully and now i want to save it to file i use $dom->save("myfile.xml"); the file myfile.xml contains only empty tags !!! like <?xml version="1.0" encoding="UTF-8"?> <person><person> </person><person></person></person> <person><person></person></person> any idea where is the wrong ? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/ Share on other sites More sharing options...
facets Posted January 4, 2008 Share Posted January 4, 2008 You'll need to supply more code for us to help you debug. Was there anything useful in your error logs? Also, are you using Firebug? It should help with debugging. Wi|| Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/#findComment-430830 Share on other sites More sharing options...
seco Posted January 5, 2008 Author Share Posted January 5, 2008 thanks for reply the code that generates the xml is success and when i use $dom->saveXML() it is dumped to the page successfully both (data and structure) but when i use $dom->save just the structure is saved to my xml file !! i want to dump data and structure to xml file thanks Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/#findComment-430934 Share on other sites More sharing options...
seco Posted January 5, 2008 Author Share Posted January 5, 2008 when i remove the encoding from the dom $dom = new DOMDocument('1.0'); it creates the file but the data doesn't appear well (non english) i try to use UTF-8 $dom = new DOMDocument('1.0','utf-8'); it dumps only the structure !!! thanks. Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/#findComment-430959 Share on other sites More sharing options...
facets Posted January 5, 2008 Share Posted January 5, 2008 Sounds like an encoding issue of sorts. Can you post more code, perhaps even the file you are running, that way we can see what else is going on? Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/#findComment-430981 Share on other sites More sharing options...
seco Posted January 5, 2008 Author Share Posted January 5, 2008 thanks for reply here is the code that generates the xml <?php $dom = new DOMDocument('1.0','UTF-8'); //$dom->formatOutput=true; $root = $dom->createElement('diagram'); $root=$dom->appendChild($root); do{ if($row_Recordset1['parent_id']==0){ $element = $dom->createElement('node', $row_Recordset1['name']); $parent=$root->appendChild($element); add($parent,$row_Recordset1['id'],$dom); } }while($row_Recordset1=mysql_fetch_assoc($Recordset1)); echo $dom->saveXML(); $dom->save('aaa.xml'); ////////////////////////////////////////////////////////////////// function add($person,$id,$dom) { mysql_select_db($GLOBALS['$database_family_con'], $GLOBALS['family_con']); $query_Recordset2 = "SELECT * FROM persons"; mysql_query("set names 'cp1256';"); $result = mysql_query($query_Recordset2, $GLOBALS['family_con']) or die(mysql_error()); $row_result = mysql_fetch_assoc($result); do{ if($row_result['parent_id']==$id) { $child=$GLOBALS['dom']->createElement('node', $row_result['name']); $child=$person->appendChild($child); add($child,$row_result['id'],$dom); } }while($row_result=mysql_fetch_assoc($result)); } ?> when i use UTF-8 encoding as above the function echo $dom->saveXML(); generates data well but the function $dom->save('aaa.xml'); generates empty nodes !!! like <?xml version="1.0" encoding="utf-8"?> <diagram><node><node><node></node></node><node></node><node><node></node></node></diagram> and when i use windows-1256 encoding it gives me warning says:- Warning: DOMDocument::saveXML() [function.DOMDocument-saveXML]: output conversion failed and if i leave the encoding empty it generates data like Ljч季 ??? and it should be arabic language thats all . thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/#findComment-431094 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.