fubowl Posted August 25, 2010 Share Posted August 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211675-fatal-error-call-to-undefined-function-simplexmlelement-help/ Share on other sites More sharing options...
fubowl Posted August 27, 2010 Author Share Posted August 27, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/211675-fatal-error-call-to-undefined-function-simplexmlelement-help/#findComment-1104223 Share on other sites More sharing options...
DarthCoder Posted May 12, 2012 Share Posted May 12, 2012 I was having the same issue, but realized that SimpleXMLElement was an object not a Function. The correct syntax should have been: $books = new SimpleXMLElement($data); Cheers Quote Link to comment https://forums.phpfreaks.com/topic/211675-fatal-error-call-to-undefined-function-simplexmlelement-help/#findComment-1344997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.