Newbie Simple_xml_load problem
Posted: Tue Jan 18, 2011 3:26 pm
Hello all,
I'm currently working my way through a PHP workbook and could do with some help. Basically I'm parsing the following XML file:
<control>
<view>main</view>
<view status="CMD_OK">main</view>
<view status="CMD_ERROR">error</view>
<command name="ListVenues">
<view>listvenues</view>
</command>
<command name="QuickAddVenue">
<classalias name="AddVenue" />
<view>quickadd</view>
</command>
</control>
using this code as part of an application class:
private function getOptions() {
$this->ensure( file_exists( $this->config ),
"Could not find options file" );
$options = @SimpleXml_load_file( $this->config );
$this->ensure( $options instanceof SimpleXMLElement,
"Could not resolve options file" );
}
and
private function ensure( $expr, $message ) {
if ( ! $expr ) {
throw new \woo\base\AppException( $message );
}
}
where $options refers to the location of the afforementioned XML file. The thing is that the line:
$this->ensure( $options instanceof SimpleXMLElement,
"Could not resolve options file" );
}
throws an exception and I don't understand why. I thought that the simpleXML_load_file returned a simpleXMLElement on success. Maybe I'm missing something really obvious but can someone explain to me what's happening? I can post more code if necessary.
Thanks in advance.
Mr Magoo
I'm currently working my way through a PHP workbook and could do with some help. Basically I'm parsing the following XML file:
<control>
<view>main</view>
<view status="CMD_OK">main</view>
<view status="CMD_ERROR">error</view>
<command name="ListVenues">
<view>listvenues</view>
</command>
<command name="QuickAddVenue">
<classalias name="AddVenue" />
<view>quickadd</view>
</command>
</control>
using this code as part of an application class:
private function getOptions() {
$this->ensure( file_exists( $this->config ),
"Could not find options file" );
$options = @SimpleXml_load_file( $this->config );
$this->ensure( $options instanceof SimpleXMLElement,
"Could not resolve options file" );
}
and
private function ensure( $expr, $message ) {
if ( ! $expr ) {
throw new \woo\base\AppException( $message );
}
}
where $options refers to the location of the afforementioned XML file. The thing is that the line:
$this->ensure( $options instanceof SimpleXMLElement,
"Could not resolve options file" );
}
throws an exception and I don't understand why. I thought that the simpleXML_load_file returned a simpleXMLElement on success. Maybe I'm missing something really obvious but can someone explain to me what's happening? I can post more code if necessary.
Thanks in advance.
Mr Magoo