0

How do I create this type of XML output using PHP?

<Root>
 <base>  rushi </base>
 <base> stack </base>
 <base> overflow </base>
<root>
sepp2k
  • 363,768
  • 54
  • 674
  • 675
Rishi Jogle
  • 277
  • 4
  • 6
  • 10
  • you add a `?>` tag and just write it down. Please be more specific what kind of solution you are looking for. On a sidenote, your XML is invalid. The root node is not closed. XML is case-sensitive. – Gordon Nov 17 '10 at 08:00
  • related and possible duplicate: [What is the best approach to using XML in PHP](http://stackoverflow.com/questions/2060346/php-what-is-the-best-approach-to-using-xml-need-to-create-and-parse-xml-response) – Gordon Nov 17 '10 at 08:03
  • *(reference)* http://de.php.net/manual/en/refs.xml.php – Gordon Nov 17 '10 at 08:11

3 Answers3

7

Have a look at:

Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
3

Here is line by line code..Hope this will help you

http://code.google.com/apis/maps/articles/phpsqlajax.html

PHP
  • 1,699
  • 5
  • 24
  • 43
2
$employees = array(
    '0'=> array(
         'name' =>'abin',
          'age' => '23',
      ),
    '1' => array(
        'name' => 'savin',
        'age'  => '24',
    )
);
//$file = fopen('file.xml','w');
$xml = new SimpleXMLElement('<employees></employees>');
foreach($employees as $employ):
$xml->addChild('name',$employ['name']);
$xml->addChild('age',$employ['age']);
endforeach;
file_put_contents('file.xml',$xml->saveXML());
Abin John
  • 381
  • 2
  • 7