I've gone over the code a million times, and I've even downloaded the code from this website and still can't seem to get it to work. Can anyone help me. The code is:
PHP Code:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Adding an Element to an XML File with the DOM Extension</title>
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<body>
<h1>Adding an Element to an XML File with the DOM Extension</h1>
<pre>
<?php
// Load XML file
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->load( "./stock_list.xml" );
$doc->formatOutput = true;
// Get the stocklist root element
$stockListElements = $doc->getElementsByTagName( "stockList" );
$stockList = $stockListElements->item( 0 );
// Create a new "item" element and add it to the stocklist
$item = $doc->createElement( "item" );
$item->setAttribute( "type", "vegetable" );
$stockList->appendChild( $item );
// Create the item's "name" child element
$name = $doc->createElement( "name", "carrot" );
$item->appendChild( $name );
// Create the item's "unitprice " child element
$unitPrice = $doc->createElement( "unitPrice", "0.79" );
$item->appendChild( $unitPrice );
//Create item's quantity element
$quantity = $doc->createElement( "quantity", "31" );
$item->appendChild( $quantity );
// Create item's description element
$description = $doc->createElement( "description" );
$item->appendChild( $description );
$cdata = $doc->createCDATASection( "Carrots are crunchy" );
$description->appendChild( $cdata );
//Output the XML document, encoding markup characters as needed
echo htmlspecialchars( $doc->saveXML() );
?>
</pre>
</body>
</html>
Thanks