0
問題
你好,我想通過使用XPATH得到一個元素。我已經使用xmlHTTP.open命令在變量XML中存儲了我獲取的XML。但是,我不知道如何使用XPATH獲取存儲在變量中的XML中的元素。XML存儲爲變量。如何通過XPATH獲取變量中的元素?
有什麼建議嗎?
下面是代碼:
var XML;
var Day;
function httpGet(location,week,day){
var xmlHttp = null;
Day = day;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.bsd.ufl.edu%2Fdining%2FMenus%2FdinHallMenu.aspx%3Flocid%3D"+location+"%26ms%3D"+week+"%26%22&format=xml&diagnostics=true&callback=", false);
xmlHttp.send(null);
XML = xmlHttp.responseText;
console.log(XML)
getResults();
}
function getResults(){
var getElementByXpath = function(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
};