Listing 1416
Submitted by PJ, 3 July 2008
/**
* constructs the element
* @param string $docType
* @param string $encoding
* @param string $name optional name
* @return GLB_Document_DocType
*/
public function __construct($docType, $encoding='UTF-8', $name=''){
$this->_encoding = $encoding;
$this->_docType = $docType;
$this->_name = $name;
foreach (glob("Element/*.php") as $filename) {
require_once($filename);
}
$this->getDOM('dom.xml');
if(!file_exists($docType)) trigger_error($docType . ' is not a valid docType', E_USER_ERROR);
$this->_docType = $docType;
switch(strtolower($docType)){
case 'xcsxml':
require_once('xcsXML.php');
$obj = new GLB_Document_xcsXML($this);
break;
case 'html':
require_once('HTML.php');
$obj = new GLB_Document_HTML($this);
break;
}
return $obj;
}
function setDocType($docType){
if(!file_exists($docType)) trigger_error($docType . ' is not a valid docType', E_USER_ERROR);
switch(strtolower($docType)){
case 'xcsxml':
require_once('xcsXML.php');
$obj = new GLB_Document_xcsXML($this);
break;
case 'html':
require_once('HTML.php');
$obj = new GLB_Document_HTML($this);
break;
}
return $obj;
}
##################################################################
$doc = new GLB_Document('HTML');
echo '1: '.get_class($doc).'<br/>';
echo '2: '.get_class($doc->setDocType('HTML'));
OUTPUT: ##########################################################
1: GLB_Document
2: GLB_Document_HTML
