我有一个如下的 XML 文件:
<products>
<handle id = "B1-12">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Del Mar Handle in Venetian Bronze</full_name>
<partial_name>Baldwin Del Mar</partial_name>
</handle>
<handle id = "B2-12">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Elizabeth Handle in Venetian Bronze</full_name>
<partial_name>Baldwin Elizabeth</partial_name>
</handle>
<handle id = "B3-12">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin New Hampshire Handle in Venetian Bronze</full_name>
<partial_name>Baldwin New Hampshire</partial_name>
</handle>
<handle id = "B4-12">
<single_price>230</single_price>
<double_price>460</double_price>
<full_name>Baldwin Westcliff Handle in Venetian Bronze</full_name>
<partial_name>Baldwin Westcliff</partial_name>
</handle>
<handle id = "B1-49">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Del Mar Handle in Matte Brass & Black</full_name>
<partial_name>Baldwin Del Mar</partial_name>
</handle>
<handle id = "B2-49">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Elizabeth Handle in Matte Brass & Black</full_name>
<partial_name>Baldwin Elizabeth</partial_name>
</handle>
<handle id = "B3-49">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin New Hampshire Handle in Matte Brass & Black</full_name>
<partial_name>Baldwin New Hampshire</partial_name>
</handle>
<handle id = "B4-49">
<single_price>230</single_price>
<double_price>460</double_price>
<full_name>Baldwin Westcliff Handle in Matte Brass & Black</full_name>
<partial_name>Baldwin Westcliff</partial_name>
</handle>
<handle id = "B1-52">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Del Mar Handle in Matte Antique Nickel</full_name>
<partial_name>Baldwin Del Mar</partial_name>
</handle>
<handle id = "B2-52">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin Elizabeth Handle in Matte Antique Nickel</full_name>
<partial_name>Baldwin Elizabeth</partial_name>
</handle>
<handle id = "B3-52">
<single_price>265</single_price>
<double_price>530</double_price>
<full_name>Baldwin New Hampshire Handle in Matte Antique Nickel</full_name>
<partial_name>Baldwin New Hampshire</partial_name>
</handle>
<handle id = "B4-52">
<single_price>230</single_price>
<double_price>460</double_price>
<full_name>Baldwin Westcliff Handle in Matte Antique Nickel</full_name>
<partial_name>Baldwin Westcliff</partial_name>
</handle>
<handle id = "P1">
<single_price>350</single_price>
<double_price>600</double_price>
<full_name>Pull Handle 1</full_name>
<partial_name>Pull Handle 1</partial_name>
</handle>
<handle id = "P3">
<single_price>350</single_price>
<double_price>600</double_price>
<full_name>Pull Handle 2</full_name>
<partial_name>Pull Handle 2</partial_name>
</handle>
<handle id = "P4">
<single_price>350</single_price>
<double_price>600</double_price>
<full_name>Pull Handle 3</full_name>
<partial_name>Pull Handle 3</partial_name>
</handle>
</products>
我试图让句柄项目稍后使用数据。但是,它似乎在第五项上失败了。当我这样做时:
var xml = new XMLHttpRequest();
xml.onreadystatechange = function ()
{
if(xml.readyState == 4)
{
var xmlDoc = xml.responseXML;
if(!xmlDoc)
xmlDoc = (new DOMParser()).parseFromString(xml.responseText, 'text/xml');
var handle_list = xmlDoc.getElementsByTagName("handle");
console.log(handle_list);
}
}
我在控制台中收到这个:
[handle, handle, handle, handle, handle, item: function]
0: handle
1: handle
2: handle
3: handle
4: handle
length: 5
__proto__: NodeList
此外,日志中索引 4 处的项目不完整。我在这里做错了什么?