inside a computer....Ok, here is my question.
I'm creating a PHP object that will echo out a XML document. I'm putting in a date/time stamp as a default. I'm starting out using the constructor to generate the time stamp.
The roadblock I've hit is how to to use different methods to access the XML document that was created inside the constructor. I'm trying to expand my knowledge about OOP so a nudge in the right direction would be appreciated.
<?php //XML DOM OBJECT CREATOR 9000
// Create new DOM object
$dom = new Xmlstuff;
$dom->generateError('This is the error');
$dom->addtime();
$dom->generateXML();
class Xmlstuff extends DOMDocument{
//Constructor
public function __construct(){
//Calling constructor of DOMDocument
parent::__construct('1.0','utf-8');
} //End of constructor
function generateError($errorMsg){
//Generate standard response
//Root Node
$rootNode= $this->createElement('root','');
$this->appendChild($rootNode);
//status Node
$statusNode=$this->createElement('status',' ');
$rootNode->appendChild($statusNode);
//Error Message
$errorElement=$this->createElement('error' ,$errorMsg);
$statusNode->appendChild($errorElement);
//date
$dateElement=$this->createElement('date', date("d/m/Y"));
$statusNode->appendChild($dateElement);
//time
//$timeElement=$this->createElement('time', date("H:i:s").' PST');
//$statusNode->appendChild($timeElement);
}
function addtime(){
//time
$timeElement=$this->createElement('time', date("H:i:s").' PST');
$statusNode->appendChild($timeElement);
}
//Function to display generated XML document
function generateXML(){
header('Content-Type: text/xml');
echo $this->saveXML();
}
} //End of Class
?>
$this