Jump to content

how to save xml to a file


seco

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/84546-how-to-save-xml-to-a-file/
Share on other sites

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

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 &#x1C8;&#x447;&#x5B63;  :(  ??? and it should be arabic language

 

thats all .

 

thanks in advance.

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.