Click to See Complete Forum and Search --> : domdocument to create xml from self join table
Hi
i have self join table and i want to use domdocument to recusivly iterate through it to create xml file
my table like
-----------------------
id | parent_id | name
-----------------------
the parent_id contains the id of the row the is the parent to it
im just new to xml any help how to write it?
thanks in advance?
and im using dreamweaver
i try the following code
<?php
$dom = new DOMDocument('1.0', 'UTF-8');
do{
if($row_Recordset1['parent_id']==0){
$element = $dom->createElement('person', $row_Recordset1['name']);
$parent=$dom->appendChild($element);
add($parent,$row_Recordset1['id']);
}
}while($row_Recordset1=mysql_fetch_assoc($Recordset1));
echo $dom->saveXML();
function add($person,$id)
{
mysql_data_seek($GLOBALS['Recordset2'],0);
do{
if($GLOBALS["row_Recordset2['parent_id']"]==$id)
{
$child=$GLOBALS['dom']->createElement('person', $GLOBALS["row_Recordset2['name']"]);
$child=$person->appendChild($child);
add($child,$GLOBALS["row_Recordset2['id']"]);
}
}while($GLOBALS['row_Recordset2']=mysql_fetch_assoc($GLOBALS['Recordset2']));
}
?>
it just outputs the parents only !!!! like
father1
father2
no recursive iteration !! why? is something wrong ?
thanks in advance.
when i remove the encoding from the dom
$dom = new DOMDocument('1.0');
it creates the file but the data doesn't appear well obfuscated(non english characters)
i try to use UTF-8 encoding
$dom = new DOMDocument('1.0','utf-8');
it dumps only the structure !!! no data
thanks.