0

I am very beginner to PHP. I want to create an XML file dynamically and i know how to do that. But here in this case, in the XML file, one node should contain an attribute "name" with a value from $_POST variable. How to write PHP code for creating XML file which contain a node with attribute "name".

Jesse
  • 8,605
  • 7
  • 47
  • 57
  • 1
    Duplicates: http://stackoverflow.com/questions/2038535/php-create-new-xml-file-and-write-data-to-it, http://stackoverflow.com/questions/3212982/need-to-write-xml-using-php-how – elclanrs Apr 26 '13 at 04:53
  • 2
    Guys, I got answer from this link. And this is what i needed. http://php.net/manual/en/domdocument.createattribute.php Thanks. – user2322331 Apr 26 '13 at 04:58

2 Answers2

0

It might be helpful for you:

<?php
// Send the headers
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

echo '<xml>';

// echo some dynamically generated content here


echo '</xml>';

?>

And finally save file with .php extension

Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57
0
 As a solution to your problem please try executing following example code snippet 

The below code snippet is created on basis of assumption that there is a form for user registration containing fields such as email ,address depicting the procedure for dynamically generation of **xml** content using php

 <?php
     $xmlstring='<xml>';
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
      $xmlstring.='<user>
     <email>'.$POST['email'].'</email>
     <address>'.$_POST['address'].'</address>
     </user>';
    }
    $xmlstring.='</xml>';
    header('Content-type:text/xml');
    echo $xmlstring;
    die;
?>
Rubin Porwal
  • 3,736
  • 1
  • 23
  • 26