PHP convert Array with SimpleXMLElement Object to XML -


i have array simplexmlelement objects inside , need formed xml ajax interaction, how can do?

this array:

array (     [0] => simplexmlelement object (           [count] => 2            [id] => 20            [user_id] => 2            [title] => polo rl )     [1] => simplexmlelement object (            [count] => 3            [id] => 19            [user_id] => 4            [title] => tshirt fitch )     [2] => simplexmlelement object (            [count] => 2            [id] => 18            [user_id] => 2            [title] => polo la martina )  )  

i xml result:

<root>     <record>         <count>2</count>         <id>20</id>         <user_id>2</user_id>         <title>polo rl</title>     </record>     <record>         <count>3</count>         <id>19</id>         <user_id>4</user_id>         <title>tshirt fitch</title>     </record>     <record>         <count>2</count>         <id>18</id>         <user_id>2</user_id>         <title>polo la martina</title>     </record> </root> 

i use simplexmlelement's asxml method output xml of each object.so this:

$xml = <<<xml <record>     <count>2</count>     <id>20</id>     <user_id>2</user_id>     <title>polo rl</title> <record>     xml;  $xml = new simplexmlelement($xml);  echo $xml->asxml(); 

will output this:

<record>     <count>2</count>     <id>20</id>     <user_id>2</user_id>     <title>polo rl</title> <record> 

so can loop through array outputing each elements xml variable so:

$fullxml = '<root>'; foreach($arrxml $xmlelement){     $fullxml .= str_replace('<?xml version="1.0"?>', '',$xmlelement->asxml()); } $fullxml .= '</root>'; echo $fullxml ; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -