<<help select search xml source with dropdown>> code inside!
Hello guys! here is a search code that was working fine until now.. =( what im trying to do is to select the xml source to be searched using a dropdown.. but now i dont know what's wrong.. just take a look, and let me know if you get it right.. thxx! =)
note: the problem must be on loading the xml and/or dropdown select,, not on the search code...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Search XML</title>
<script type="text/javascript">
window.onload = loadIndex;
function loadIndex() { // load indexfile
// most current browsers support document.implementation
if (document.implementation && document.implementation.createDocument) {
var docdoc = document.getElementById('urlfile').value;
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load(docdoc);
}
// MSIE uses ActiveX
else if (window.ActiveXObject) {
var docdoc = document.getElementById('urlfile').value;
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(docdoc);
}
}
function searchIndex() { // search the index (duh!)
if (!xmlDoc) {
loadIndex();
}
// get the search term from a form field with id 'searchme'
var searchterm = document.getElementById("searchme").value;
var allitems = xmlDoc.getElementsByTagName("item");
results = new Array;
if (searchterm.length < 2) {
alert("Please enter at least 2 digits");
}
else {
for (var i=0;i<allitems.length;i++) {
// see if the XML entry matches the search term,
// and (if so) store it in an array
var name = allitems[i].lastChild.nodeValue;
var exp = new RegExp(searchterm,"i");
if ( name.match(exp)!= null) {
results.push(allitems[i]);
}
}
// send the results to another function that displays them to the user
showResults(results, searchterm);
}
}
// Write search results to a table
function showResults(results, searchterm) {
if (results.length > 0) {
// if there are any results, write them to a table
XML Parsing Error: XML or text declaration not at start of entity
Location: http://poligoma.webs.com/XML/index.xml
Line Number 3, Column 1:<?xml version="1.0" encoding="utf-8"?>
^
XML Parsing Error: XML or text declaration not at start of entity
Location: http://poligoma.webs.com/XML/index.xml
Line Number 3, Column 1:<?xml version="1.0" encoding="utf-8"?>
^
it must only remove whitespaces and newlines before xml prolog, which must start in first column of the first row, in rest is well formated I guess.