Skatecrazy1 Posted October 18, 2006 Share Posted October 18, 2006 Hey i'm kind of new to the whole XML/PHP thing, and I was trying some code out of a book that surprisingly didn't work. Here is the short XML File:[code]<?xml version = "1.0" encoding = "iso-8859-1" ?><books> <title> <topic>JavaScript</topic> <series>in easy steps</series> </title> <title> <topic>C++Programming</topic> <series>in easy steps</series> </title> </books>[/code]and here is the PHP[code]<html><head><title>Reading DOM</title></head><body><?php//load xml document into the DOM $dom = new DomDocument; $dom->load( "books.xml" ); //print out the root element name echo("Root element name is: "); echo( $dom -> documentElement -> nodeName ); echo("of the people in the XML file."); echo( "<hr>" ); //print a list of names echo("Topics include:<ul>"); $topics = $dom -> getElementsByTagName( "topic" ); foreach($topics as $node) { echo("<li>" . $node -> textContent . "</li>"); } echo( "</ul>" ); ?></body></html>[/code]and when i try to use that code to parse the XML, i get this error[quote]Warning: domdocument() expects at least 1 parameter, 0 given in /home/content/s/n/a/snapskate/html/v2/pg/xmltest.php on line 5Fatal error: Call to undefined function: load() in /home/content/s/n/a/snapskate/html/v2/pg/xmltest.php on line 6[/quote]does anyone know what's up? Quote Link to comment Share on other sites More sharing options...
btherl Posted October 18, 2006 Share Posted October 18, 2006 Which version of PHP are you using? PHP4 uses the DOM XML extension, PHP5 uses the DOM extension, each which appear to have the same object names with different interfaces. Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 18, 2006 Author Share Posted October 18, 2006 I'm not exactly sure, but could you show me which version uses what so I can try both? Quote Link to comment Share on other sites More sharing options...
edg322 Posted October 18, 2006 Share Posted October 18, 2006 yeah create a file called info.php and use <?php phpinfo(); ?> this will tell you the version and DOM/XML info too Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 19, 2006 Author Share Posted October 19, 2006 okay here's my php info [url=http://www.snapskate.com/info.php]http://www.snapskate.com/info.php[/url]i can't really get anything from it as to why my code to parse the xml isn't working, so if anyone knows I'd appreciate some insight :Papparently goDaddy still uses php 4 Quote Link to comment Share on other sites More sharing options...
btherl Posted October 20, 2006 Share Posted October 20, 2006 Ok, php4 will be using the DOM XML extension, but that code you are trying is for DOM, which is with php5. There's some examples for using DOM XML here:http://www.php.net/manual/en/ref.domxml.phpTake a look in the user comments at the bottom of that page for some examples.Good luck :) Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 20, 2006 Author Share Posted October 20, 2006 so what would i replace my $dom = new DomDocument; with, in this case? Quote Link to comment Share on other sites More sharing options...
btherl Posted October 20, 2006 Share Posted October 20, 2006 Look at how the domDocument object is created here: http://www.php.net/manual/en/ref.domxml.php#61088Instead of using "new", it's returned from a function call. eg $domDocument = domxml_open_mem($string) will create a domDocument from a string. Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 20, 2006 Author Share Posted October 20, 2006 okay, thanks for the help, butcalled godaddy, found out upgrading to the new server configuration (and PHP 5) was an option i had not yet enabled.but, I used what you said and it worked fine.thanks though. Quote Link to comment 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.