See the whole code in the bottom of this message.
This line:
$node = $this->Fvariables->SelectSingleNode ($varname);
creates no problem for existing node names.
But if no node exists with this name ($varname), then this line -- no matter how I tried to handle errors -- breaks the script execution exactly at this point. The error message: Fatal error: NULL pointer exception in clsXmlDoc.php on line ##
I run the script under WinNT4 using a batch command
php clsXmlDoc.php>aa.htm
Is there any way to handle NULL returns from SelectSingleNode method?
Complete code:
<?
$doc = new TxmlDoc();
$doc->loadFile ("test.xml");
print "\n<br>Age: " .$doc->getVar ("Age") ."<br>\n";
//--------------------------- XMLDOM implementation -----------------------------
class TxmlDoc {
var $Fdoc, $Froot, $Fvariables, $Farrays, $filename;
function TxmlDoc() {
$this->Fdoc = new COM ("Microsoft.XMLDOM");
$this->Fdoc->async = false;
$this->filename = "";
}
function loadFile ($filename) {
if (file_exists($filename)) {
$this->Fdoc->load ($filename);
$this->Froot = $this->Fdoc->SelectSingleNode ("/root");
$this->Fvariables = $this->Froot->SelectSingleNode ("variables");
$this->Farrays = $this->Froot->SelectSingleNode ("arrays");
}
}
function getVar ($varname) {
$node = $this->Fvariables->SelectSingleNode ($varname);
return $node->text;
}
}
?>