2011-12-16 36 views
2

我的網站調用web服務,web服務返回一個xml。當我試圖通過使用在javascript getElementsByTagName('*tag name*')返回的XML解析,Safari瀏覽器提供了以下錯誤:GetElementsByTagName不能在XML上工作

TypeError: 'undefined' is not a function (evaluating 'xmlDoc.getElementsByTagName('application_id')')

有誰知道爲什麼會這樣? XML在Internet Explorer上解析得很好。

我的JS:

function GetValuesFromXML(xmlText) { 
    var string = xmlText.responsexml; 

    var xmlDoc = xmlText.responseXML; 
    var appIdArray = xmlDoc.getElementsByTagName('application_id'); 
    document.write(appIdArray[0].xml); 
} 

xmlText是獲取由web服務返回的xmlhttprequest

+0

請發佈完整的JS代碼。 – 2011-12-16 21:25:55

回答

0

文檔是一個接口,而不是文檔對象的實例。使用createDocument創建一個對象,然後將響應XML添加到文檔中:

var dom = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null); 
dom.firstChild.appendChild(dom.createCDATASection(xmlDoc)); 
相關問題