I have trouble to display xml in php. before it, i converted an array code to xml.
i got array result from oci_fetch_array
while ($data = oci_fetch_array($stmt, OCI_BOTH)) {
$parent = $data['PARENT'];
if($data['PARENT'] == 0) {
$idx++;
$idx2 = 0;
$product[$idx]['text'] = $data['NAME'];
$product[$idx]['cls'] = "folder";
} else {
$product[$idx]['children'][$idx2]['id'] = $data['ID'];
$product[$idx]['children'][$idx2]['name'] = $data['NAME'];
$product[$idx]['children'][$idx2]['code'] = $data['CODE'];
$idx2++;
}
}
And this is the array result:
Array
(
[-1] => Array
(
[children] => Array
(
[] => Array
(
[id] => 4
[name] => SPEEDY 384 KB
[code] => SPEEDY_384KB
)
[1] => Array
(
[id] => 7
[name] => SPEEDY 2 MB
[code] => SPEEDY_2MB
)
)
)
)
then i used php code to convert it into xml, this is the code:
$product2=array($product);
$xml = new SimpleXMLElement("<services/>");
array_walk_recursive($product2, array ($xml, 'addChild'));
$string=$xml->asXML();
echo '<pre>', htmlentities($string), '</pre>';
yes, i got result but it's not what i hope. this is the result...
<?xml version="1.0"?>
<services>
<4>id</4>
<SPEEDY YOO>name</SPEEDY YOO>
<SPEEDY_LOO>code</SPEEDY_LOO>
<7>id</7>
<2 MB>name</ 2 MB>
<U2MB>code</U2MB>
</services>
the result that i want is like this:
<?xml version="1.0"?>
<services>
<id>4</id>
<name>SPEEDY YOO</name>
<code>SPEEDY_LOO</code>
<id>7</id>
<name>2 MB</name >
<code>U2MB</code>
</services>
how can i get the right one? help me, thanks