-1
財產 '的childNodes' 我運行到一個XML文件中像這樣的請求:無法讀取的不確定
function load()
{
var request = new XMLHttpRequest();
request.open("GET", "response.xml", true);
request.send();
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
var x = request.responseXML;
var y = x.getElementsByTagName("Limits")[0].childNodes[1];
var z = y.getElementsByTagName("Limits")[0].childNodes[0];
document.write(z);
}
};
}
的XML response.xml
是這樣的:
<Factory>
<Limits>
<Point X="92" Y="489">hahahahff</Point>
<Point X="570" Y="487">1111</Point>
<Point X="570" Y="138">33333</Point>
<Point X="92" Y="140">44444444</Point>
<Point X="92" Y="139">5555555</Point>
</Limits>
<Cells>
<Cell>
<Point X="358" Y="138"/>
<Point X="361" Y="487"/>
<Point X="570" Y="487"/>
<Point X="570" Y="138"/>
<Point X="358" Y="138"/>
</Cell>
<Cell>
<Point X="311" Y="139"/>
<Point X="311" Y="488"/>
<Point X="92" Y="489"/>
<Point X="92" Y="140"/>
<Point X="311" Y="139"/>
</Cell>
</Cells>
</Factory>
我得到這個錯誤:
Cannot read property 'childNodes' of undefined
爲什麼會發生這種情況?
我試圖實現的是打印第二個POINT
節點的值,而不使用getElementsByTagName("POINT")[1]
。
基本上我想'進入'限制節點,並打印第二個值。
該錯誤表示'getElementsByTagName'返回空列表。 – Barmar 2014-11-02 08:39:08