javascript的程序,请帮忙解读一下
function Yahoo_Search() {}Yahoo_Search.baseURL = function () {
return "http://api.search.
}
Yahoo_Search.appid = function () {
return "YahooSearchSidebar";
}
Yahoo_Search.baseArgs = function () {
return "appid=" + this.appid();
}
[bold][underline]Yahoo_Search.Results = function (args) {
var xmlUrl = this.baseURL() + "webSearch?"
+ this.baseArgs()
+ "&query=" + args["Doc"]
+ "&zip="
+ "&start=" + args["First"]
+ "&results=" + args["Count"];
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", xmlUrl, false);
xmlhttp.send(null);
return this.readXML(xmlhttp.responseXML);
}[/underline][/bold]
[bold][underline]Yahoo_Search.readXML = function (xmlDoc)[/underline][/bold] {
try {
var retVal = new Array();
var resultSet = xmlDoc.getElementsByTagName("ResultSet")[0];
var totalResultsAvailable = parseInt(resultSet.getAttribute("totalResultsAvailable"));
var totalResultsReturned = parseInt(resultSet.getAttribute("totalResultsReturned"));
var firstResultPosition = parseInt(resultSet.getAttribute("firstResultPosition"));
var start = firstResultPosition;
var end = firstResultPosition + totalResultsReturned - 1;
var results = xmlDoc.getElementsByTagName("Result");
for (var i = 0; i < results.length; i++) {
var result = results[i];
var title = result.getElementsByTagName(Title)[0].firstChild.nodeValue;
var summary = ;
if (result.getElementsByTagName(Summary)[0].firstChild) {
summary = result.getElementsByTagName(Summary)[0].firstChild.nodeValue;
}
var clickUrl = result.getElementsByTagName(ClickUrl)[0].firstChild.nodeValue;
var url = result.getElementsByTagName(Url)[0].firstChild.nodeValue;
retVal[i] = { I: start + i, Title: title, Summary: summary, ClickUrl: clickUrl, Url: url };
}
return retVal;
} catch(exception) {
alert(Exception occurred while reading XML (i= + i + ; start= + start + ;end= + end + ): + exception);
}
}
昨天开始学这个程序,上面画线部分不太明白,那位高人给指点一下?看懂这个之后,准备用java改一个,不知道能不能成功,有经验的朋友请帮忙……