0

次のような 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>

後でデータを使用するためにハンドル項目を取得しようとしています。ただし、5番目の項目で失敗しているようです。私がこれを行うとき:

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 の項目は不完全です。ここで何が間違っていますか?

4

1 に答える 1

1

この質問を回答済みとしてマークできる回答のように思われるので、コメントを回答として追加します。

パーサーが停止するタグの周囲のxmlファイルにエスケープされていないアンパサンドがあります。おそらくそれがあなたの問題の原因ですか?

于 2013-03-18T09:35:52.397 に答える