Allora, la classe:
Codice PHP:
class taskManager {
private $dom;
private $xmlHandler;
private $xslHandler;
private $output;
public function __construct() {
$this->dom = new DOMDocument();
$section = (!isset($_GET['x'])) ? 'index' : trim($_GET['x']);
if ($this->__loadXmlDoc($section) && $this->__loadXslDoc($section)) {
$processor = new XsltProcessor();
$processor->importStylesheet($this->xslHandler);
$this->output = $processor->transformToDoc($this->xmlHandler);
} else {
//i file che vuoi caricare non esistono!!!
throw new Exception('Error - You are trying to process the wrong section for your site!!!');
}
}
private function __loadXmlDoc($section) {
$file = DIR_PATH . '/content/' . $section . '.xml';
if ($this->xmlHandler = $this->dom->load($file)) {
return TRUE;
}
return FALSE;
}
private function __loadXslDoc($section) {
$file = DIR_PATH . '/structure/' . $section . '.xsl';
if ($this->xslHandler = $this->dom->load($file)) {
return TRUE;
}
return FALSE;
}
public function __showXML() {
return $this->output->saveXML();
}
}
Classe molto semplice e di facile comprensione, spero.. Prendi tramite GET il nome della sezione da caricare e in teoria, carica l'xml e l'xsl correto della sezione per poi ritornarle a browser..
L'unico problema è che:
Codice PHP:
$this->xmlHandler = $this->dom->load($file)
mi restituisce, come giusto, TRUE (1 booleano) cosa che però non va bene con
Codice PHP:
$processor->importStylesheet($this->xslHandler);
perche questo metodo vuole un'oggetto in input e non un valore booleano..
Come risolvo questo problema?? Ho provato con:
Codice PHP:
$this->xmlHandler &= $this->dom->load($file)
ma non ho avuto molta fortuna.. anzi l'errore scompare ma se ne creano altri tipo "Error - You are trying to process the wrong section for your site!!!" come se non trovasse/caricasse nessun file..
Se qualcuno ha qualche spunto ben venga...