Monday, April 9, 2007

Don't want to forget this code that should output an new .xml file from PHP

http://www-128.ibm.com/developerworks/library/x-xmlphp1.html


//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');

//add root -
$books = $dom->appendChild($dom->createElement('books'));

//add element to
$book = $books->appendChild($dom->createElement('book'));

//add element to
$title = $book->appendChild($dom->createElement('title'));

//add text node element to
$title->appendChild(
$dom->createTextNode('Great American Novel'));

//generate xml
$dom->formatOutput = true; // set the formatOutput attribute of
// domDocument to true
// save XML as string or file
$test1 = $dom->saveXML(); // put string in test1
$dom->save('test1.xml'); // save as file
?>

No comments: