Jump to content

XML Parsing


Skatecrazy1

Recommended Posts

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 5

Fatal 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?
Link to comment
https://forums.phpfreaks.com/topic/24287-xml-parsing/
Share on other sites

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 :P

apparently goDaddy still uses php 4
Link to comment
https://forums.phpfreaks.com/topic/24287-xml-parsing/#findComment-111051
Share on other sites

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.php

Take a look in the user comments at the bottom of that page for some examples.

Good luck :)
Link to comment
https://forums.phpfreaks.com/topic/24287-xml-parsing/#findComment-111662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.