Hi guys, this is my first post. Im a noob so please go easy. Basically i am trying to perform a search of authors in a xml file using a php file. I can’t seem to get it working right, but i don’t know what the error is. It displays as the following when doing a search of the author “Ritchie”. Any help would be greatly appreciated
My New Book
Notice: Trying to get property of non-object in N:\ftp\compc\d09iw\Com506\Week4\authorSearch.php on line 25
The code of the xml file is:
[code]<?xml version="1.0"?>
106 Cut the grass Mr T Ritchie 16/10/2012 When you finish your work will you cut the grass please? Insert web address Get milk Mum Ritchie 16/10/2012 When you finish your work will you buy milk please? Costcutters Wash Car Dad Ritchie 16/10/2012 Wash the car Insert web address Get haircut Nichola Ritchie 16/10/2012 Please get a hair cut!! SuperCuts Complete Uni Work Dave Ritchie 16/10/2012 Get your uni work done Ulster University [/code] [u][b]The code of the php file is:[/b][/u] [php] <?phpif (isset($_POST[“submit”])) {
$file = “memo.xml”;
$fp = fopen($file, “rb”) or die(“cannot open file”);
$str = fread($fp, filesize($file));
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML($str) or die(“Error”);
// get document element
$root = $xml->documentElement;
$memos = $root->childNodes->item(5);
$memosFound=0;
foreach($memos->childNodes as $memo) {
$memoTitleNode=$memo->childNodes->item(0);
$memoSenderNode=$memo->childNodes->item(1);
$memoRecipientNode=$memo->childNodes->item(2);
$memoDateNode=$memo->childNodes->item(3);
$memoMessageNode=$memo->childNodes->item(4);
$memoUrlNode=$memo->childNodes->item(5);
if ($memoSenderNode->nodeValue==$_POST[“sender”]) {
echo $memoTitleNode->nodeValue."
";
$memoSenderNode->nodeValue."
";
$memoRecipientNode->nodeValue."<br>";
$memoDateNode->nodeValue."<br>";
$memoMessageNode->nodeValue."<br>";
$memoUrlNode->nodeValue."<br>";
$memosFound++;
}
}
if ($memosFound==0) echo “No matching authors found”;
} else {
?>
XML Data Search