Newbie Simple_xml_load problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MrMagoo
Forum Newbie
Posts: 1
Joined: Tue Jan 18, 2011 3:11 pm

Newbie Simple_xml_load problem

Post by MrMagoo »

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
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Newbie Simple_xml_load problem

Post by Peter Kelly »

What exception is this?
Post Reply