When using PHP 5, the code changes a bit, but most of it is changing to studly caps. Creating XML with DOM (dom-write5.php; excerpt)<?php require_once 'stripFormSlashes.inc.php'; $dom = new DOMDocument(); $dom->load('quotes.xml'); $quote = $dom->createElement('quote'); $quote->setAttribute('year', $_POST['year']); $phrase = $dom->createElement('phrase'); $phraseText = $dom-> createTextNode($_POST['quote']); $phrase->appendChild($phraseText); $author = $dom->createElement('author'); $authorText = $dom-> createTextNode($_POST['author']); $author->appendChild($authorText); $quote->appendChild($phrase); $quote->appendChild($author); $dom->documentElement->appendChild($quote); $dom->save('quotes.xml'); echo 'Quote saved.'; ?>
|