<html>
<head>
<script>
var xmlHttpfunction showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").
innerHTML="";
document.getElementById("livesearch").
style.border="0px";
return
}xmlHttp=GetXmlHttpObject()if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}var url="livesearch.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("livesearch").
innerHTML=xmlHttp.responseText;
document.getElementById("livesearch").
style.border="1px solid #A5ACB2";
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
<style type="text/css">
#livesearch
{
margin:0px;
width:194px;
}
#txt1
{
margin:0px;
}
</style>
</head>
<body><form>
<input type="text" id="txt1" size="30"
onkeyup="showResult(this.value)"><div id="livesearch"></div>
</form></body>
</html><?xml version="1.0" encoding="ISO-8859-1" ?>
<!- Edited by XMLSpy®
-->
<pages>
<link>
<title>HTML DOM alt Property</title>
<url>http://www.w3school.com.cn/htmldom/prop_img_alt.asp</url>
</link>
<link>
<title>HTML DOM height Property</title>
<url>http://www.w3school.com.cn/htmldom/prop_img_height.asp</url>
</link>
<link>
<title>HTML a tag</title>
<url>http://www.w3school.com.cn/tags/tag_a.asp</url>
</link>
<link>
<title>HTML br tag</title>
<url>http://www.w3school.com.cn/tags/tag_br.asp</url>
</link>
<link>
<title>CSS background Property</title>
<url>http://www.w3school.com.cn/css/pr_background.asp</url>
</link>
<link>
<title>CSS border Property</title>
<url>http://www.w3school.com.cn/css/pr_border.asp</url>
</link>
<link>
<title>JavaScript Date() Method</title>
<url>http://www.w3school.com.cn/jsref/jsref_date.asp</url>
</link>
<link>
<title>JavaScript anchor() Method</title>
<url>http://www.w3school.com.cn/jsref/jsref_anchor.asp</url>
</link>
</pages>
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL
$q=$_GET["q"];//lookup all links from the xml file if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('title');
$z=$x->item($i)->getElementsByTagName('url');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
<head>
<script>
var xmlHttpfunction showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").
innerHTML="";
document.getElementById("livesearch").
style.border="0px";
return
}xmlHttp=GetXmlHttpObject()if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}var url="livesearch.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("livesearch").
innerHTML=xmlHttp.responseText;
document.getElementById("livesearch").
style.border="1px solid #A5ACB2";
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
<style type="text/css">
#livesearch
{
margin:0px;
width:194px;
}
#txt1
{
margin:0px;
}
</style>
</head>
<body><form>
<input type="text" id="txt1" size="30"
onkeyup="showResult(this.value)"><div id="livesearch"></div>
</form></body>
</html><?xml version="1.0" encoding="ISO-8859-1" ?>
<!- Edited by XMLSpy®
-->
<pages>
<link>
<title>HTML DOM alt Property</title>
<url>http://www.w3school.com.cn/htmldom/prop_img_alt.asp</url>
</link>
<link>
<title>HTML DOM height Property</title>
<url>http://www.w3school.com.cn/htmldom/prop_img_height.asp</url>
</link>
<link>
<title>HTML a tag</title>
<url>http://www.w3school.com.cn/tags/tag_a.asp</url>
</link>
<link>
<title>HTML br tag</title>
<url>http://www.w3school.com.cn/tags/tag_br.asp</url>
</link>
<link>
<title>CSS background Property</title>
<url>http://www.w3school.com.cn/css/pr_background.asp</url>
</link>
<link>
<title>CSS border Property</title>
<url>http://www.w3school.com.cn/css/pr_border.asp</url>
</link>
<link>
<title>JavaScript Date() Method</title>
<url>http://www.w3school.com.cn/jsref/jsref_date.asp</url>
</link>
<link>
<title>JavaScript anchor() Method</title>
<url>http://www.w3school.com.cn/jsref/jsref_anchor.asp</url>
</link>
</pages>
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL
$q=$_GET["q"];//lookup all links from the xml file if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('title');
$z=$x->item($i)->getElementsByTagName('url');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
去掉xml文件里的下面那段注释就行了
<!- Edited by XMLSpy®
-->