Hi People,
Im new to XML and Xpath, but in a website im creating for a assignment, i have to do a search by title and by category. (ive got category working)
On the title one, the user types in a word to search and should search for a match to that word.
at the moment im getting the following errors -
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Invalid expression in C:\xampp\htdocs\Brookxml\form_title.php on line 17
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in C:\xampp\htdocs\Brookxml\form_title.php on line 17
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Brookxml\form_title.php on line 21
The code for that page is -
<?php
// Create a new simplexml instance loading xml file
$tXML = simplexml_load_file('http://xml.x-alt.com/');
$param = $_GET['title'];
if ($param == "all")
{
$qry = "/channel/item/[title contains()]";
}
else{
//Construct an XPath expression,including a predicate in this instance.
$qry = "/channel/item/[title contains = '$param']";
}
//call the simplexml xpath method
$channel = $tXML->xpath($qry);
echo "<table border=\"1\">\n";
// iterate through the students returned by the xpath query
foreach ($channel as $item) {
echo "<tr>\n";
echo "<tr><td>Title</td><td>Category</td><td>Description</td><td>Link</td></tr>\n";
echo "<td>{$item->title}</td>\n";
echo "<td>{$item->category}</td>\n";
echo "<td>{$item->description}</td>\n";
echo "<td>{$item->link}</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Search_Title</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form action="index.php" method="post">
<fieldset style="width:250px"><legend>Search by Title:</legend>
<input type="text" name="title" size="20" maxlength="40" /></fieldset>
<fieldset style="width:250px"><legend></legend>
<div align="left"><input type="submit" name="submit" value="Submit" /></div></fieldset>
<hr />
</form>
</body>
</html>
Any help would be appreciated