0

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

<Root>
 <base>  rushi </base>
 <base> stack </base>
 <base> overflow </base>
<root>
3
  • 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. Commented Nov 17, 2010 at 8:00
  • related and possible duplicate: What is the best approach to using XML in PHP Commented Nov 17, 2010 at 8:03
  • (reference) de.php.net/manual/en/refs.xml.php Commented Nov 17, 2010 at 8:11

3 Answers 3

7

Have a look at:

Sign up to request clarification or add additional context in comments.

Comments

3

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

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

Comments

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());

1 Comment

This line makes the trickfile_put_contents('file.xml',$xml->saveXML());

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.