mercredi 26 novembre 2014

How To Convert Array To XML And Show It


Vote count:

0




i have result of my query and i convert them to arary. Here is it the result in array:



Array
(
[-1] => Array
(
[children] => Array
(
[] => Array
(
[leaf] => 1
[text] => HelloYou
[id] => hello
)

[1] => Array
(
[leaf] => 1
[text] => JustSay
[id] => hai
)

)

)

)


and i want the result is converted into xml, like this one...



<?xml version="1.0"?>
<test>
<service>
<leaf>1</leaf>
<text> HelloYou </text>
<id>hello</id>
</service>
<service>
<leaf>1</leaf>
<text> JustSay </text>
<id>hai</id>
</service>
</test>


i converted, and here is my php code:



$xml = new SimpleXMLElement('<services/>');
array_walk_recursive($product, array ($xml, 'addChild'));
$string=print $xml->asXML();
echo '<pre>', htmlentities($string), '</pre>';


but the result just show...



<1>leaftextid<1>leaftextid

1


how can i fix this??



asked 51 secs ago







How To Convert Array To XML And Show It

Aucun commentaire:

Enregistrer un commentaire