Jump to content

Fatal error: Call to undefined function SimpleXMLElement() Help


Recommended Posts

Using the script located here: http://www.phpfreaks.com/tutorial/handling-xml-data

 

I receive the following error: Fatal error: Call to undefined function SimpleXMLElement() in C:\...\xml.php on line 7

 

xml.php:

<?php
// Passing the XML
$data = file_get_contents("http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/album_output.php"); //loads fine

$books = SimpleXMLElement($data);

foreach($books as $book) // loop through our books
{
echo <<<EOF
<tr>
	<td>{$book->url}</td>
	<td>{$book->description}</td>
	<td>{$book->filename}</td>
</tr>

EOF;
}
?>

 

Running WAMPServer with php 5.3.0

 

phpinfo(); says:

 

Simplexml support enabled

Revision $Revision: 1.151.2.22.2.35.2.32 $

Schema support enabled

 

However, unable to find an extension for simplexml inside php.ini or httpd.conf (if it's even supposed to be in there)

 

Any help would be appreciated.

 

Well, since I received no answers, I found an alternative solution.

 

Using DOM method to access XML file:

 

  // DOMElement->getElementsByTagName() -- Gets elements by tagname
  // nodeValue : The value of this node, depending on its type.
  // Load XML File. You can use loadXML if you wish to load XML data from a string

  $objDOM = new DOMDocument();
  $objDOM->load("test.xml"); //make sure path is correct


  $note = $objDOM->getElementsByTagName("thumbnail");
  // for each note tag, parse the document and get values for
  // tasks and details tag.

  foreach( $note as $value )
  {
    $tasks = $value->getElementsByTagName("filename");
    $task  = $tasks->item(0)->nodeValue;

    $details = $value->getElementsByTagName("url");
    $detail  = $details->item(0)->nodeValue;

    echo "$task :: $detail <br>";
  }

 

where test.xml:

 

<thumbnails>
<thumbnail>
	<filename>http://thumb1</filename>
	<url>Set 1 URL</url>
	<description>Album 1</description>
</thumbnail>
<thumbnail>
	<filename>http://thumb2</filename>
	<url>Set 2 URL</url>
	<description>Album 2</description>
</thumbnail>
<thumbnail>
	<filename>http://thumb3</filename>
	<url>Set 3 URL</url>
	<description>Album 3</description>
</thumbnail>
<thumbnail>
	<filename>http://thumb4</filename>
	<url>Set 4 URL1</url>
	<description>Album 4</description>
</thumbnail>
</thumbnails>

 

or to get xml attribute:

 

// example on using the 'getAttribute()' method

$dom=new DOMDocument();

$dom->load('test2.xml');

$headlines=$dom->getElementsByTagName('thumbnail');

foreach($headlines as $headline){

echo 'ID attribute of current node is the following: '.$headline->getAttribute('filename').'<br />';

}

 

where test2.xml:

 

<thumbnails>
<thumbnail filename="http://thumb1" url="72157620019981688" description="Cat 1"/>
<thumbnail filename="http://thumb2" url="72157619839911144" description="Cat 2"/>
<thumbnail filename="http://thumb3" url="72157619840761942" description="Cat 3"/>
<thumbnail filename="http://thumb4" url="72157619935624301" description="Cat 4"/>
</thumbnails>

  • 1 year later...
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.