Warning: DOMDocument::load() [function.DOMDocument-load]: attributes construct error in file:///C%3A/wamp/www/Website/xml/library.xml, line: 1 in C:\wamp\www\Website\home.php on line 5
Warning: DOMDocument::load() [function.DOMDocument-load]: Couldn't find end of Start Tag xml line 1 in file:///C%3A/wamp/www/Website/xml/library.xml, line: 1 in C:\wamp\www\Website\home.php on line 5
Warning: DOMDocument::load() [function.DOMDocument-load]: Extra content at the end of the document in file:///C%3A/wamp/www/Website/xml/library.xml, line: 1 in C:\wamp\www\Website\home.php on line 5
Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\wamp\www\Website\home.php on line 11
I have no idea what is wrong with my code and I have checked it and can't seem to find anything wrong with it. Can anybody help me??
This is my PHP code for it:
Code: Select all
<?php
/* here we must specify the version of XML : i.e: 1.0 */
$xml = new DomDocument('1.0');
$xml->load('xml/library.xml');
/* first to create a list of categories */
$categories = array();
$XMLCategories = $xml->getElementsByTagName('categories')->item(0);
foreach($XMLCategories->getElementsByTagName('category') as $categoryNode) {
/* notice how we get attributes */
$cid = $categoryNode->getAttribute('cid');
$categories[$cid] = $categoryNode->firstChild->nodeValue;
}
?>
Code: Select all
<xml version="1.0"?>
<library>
<categories>
<category cid="1">Web Development</category>
<category cid="2">Database Programming</category>
<category cid="3">PHP</category>
<category cid="4">Java</category>
</categories>
<books>
<book>
<title>Apache 2</title>
<author>Peter Wainwright</author>
<publisher>Wrox</publisher>
<category>1</category>
</book>
<book>
<title>Advanced PHP Programming</title>
<author>George Schlossnagle</author>
<publisher>Developer Library</publisher>
<category>1</category>
<category>3</category>
</book>
<book>
<title>Visual FoxPro 6 - Programmers Guide</title>
<author>Eric Stroo</author>
<publisher>Microsoft Press</publisher>
<category>2</category>
</book>
<book>
<title>Mastering Java 2</title>
<author>John Zukowski</author>
<publisher>Sybex</publisher>
<category>4</category>
</book>
</books></library>
Thanks a million
Colm