how to put php data in xml ??

Discussion in 'XML & RSS' started by crazy.works, Feb 7, 2010.

  1. #1
    hello, iam new in xml.. so i have xml file in it data like
    
    <author> data goes here </author> 
    
    Code (markup):
    i call the xml file by JS function, so now i want to put the data between the 'author' tags from the database with php...so how can i put php inside that .xml file please ??
     
    crazy.works, Feb 7, 2010 IP
  2. mariush1007

    mariush1007 Member

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    hi,

    assuming that Your xml file looks like:

    <?xml version="1.0"?>
    <items>
    	<author> data goes here </author>
    </items>
    Code (markup):
    then You can use SimpleXML php extension to do what You want as below:

    $xmlFile = 'data.xml';
    $sxe = simplexml_load_file($xmlFile);
    $sxe->author[0] = 'new data';
    file_put_contents($xmlFile, $sxe->asXML());
    Code (markup):
    take a look here for more details:

    http://php.net/manual/en/book.simplexml.php
     
    mariush1007, Feb 7, 2010 IP