Jump to content

SimpleXMLElement Issue


Solarpitch

Recommended Posts

Hi Guys,

 

I'm trying to run the following code but the page breaks with no errors. I'm using PHP 5 which should run Simple XML. Code seems fine to me...

 

<?php
$xmlstr = "courses.xml";
$xml = new SimpleXMLElement($xmlstr); //  I Know it's breaking at this line

echo $xml->course[0]->name;
?>

Link to comment
Share on other sites

php doesn't just stop running or "breaking" as you say, without a reason (without an error).  If it is because of an error, you must have error reporting turned off in php.ini or .htaccess or somewhere. 

 

edit: also, are you sure that 3rd line of code is even returning anything?

 

 

Link to comment
Share on other sites

Ok, got the error..

 

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50

 

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: http://site.mysite.ie/wp-content/themes/iact/courses.xml in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50

 

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50

 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php:50 Stack trace: #0 /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php(50): SimpleXMLElement->__construct('http://site.iac...') #1 /var/www/vhosts/httpdocs/wp-includes/template-loader.php(43): include('/var/www/vhosts...') #2 /var/www/vhosts/httpdocs/wp-blog-header.php(16): require_once('/var/www/vhosts...') #3 /var/www/vhosts/httpdocs/index.php(17): require('/var/www/vhosts...') #4 {main} thrown in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50

Link to comment
Share on other sites

Actually, found the solution...

 

If you are passing it a filename instead of a string, the third parameter needs to be TRUE, e.g.:

 

$sxe = new SimpleXMLElement('they_wont_let_me_put_a_url_here', NULL, TRUE);

 

Thanks for your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.