2013-04-17 53 views
0

我試圖讓頭的子節點的名稱所需標籤的名稱 - >文本節點(所以我需要 Buut當我寫爲什麼我不能得到這個XML文件

var headerstyles = xmlDoc.getElementsByTagName("head")[0].getElementsByTagName("style")[0].childNodes; 

    for (i=0;i<headerstyles.length;i++) 
    { 
     alert (headerstyles[i].nodeName); 

    } 

我得到TE響應#text顏色#text字體#text

所以我不看到實際的節點名我得到這個#text 我怎麼能解決這個問題之前,瞭解whuy。

這裏是我的代碼

xmlhttp.open("GET","desc.xml",false); 
    xmlhttp.send(); 
    alert (xmlhttp.responseText); 
    xmlDoc=xmlhttp.responseXML; 
    alert (xmlDoc); 




    var headerstyles = xmlDoc.getElementsByTagName("head")[0].getElementsByTagName("style")[0].childNodes; 

    for (i=0;i<headerstyles.length;i++) 
    { 
     alert (headerstyles[i].nodeName); 

    } 

這裏是我的desc.xml

<docs> 
<main> 
    <bgrnd> 
    <img> </img> 
    <color> </color> 
    </bgrnd> 

    <head> 
    <text>Learning about Birds</text> 
    <style> 
     <color>red</color> 
     <font>italic bold 30px Georgia,serif</font> 

    </style> 
    </head> 


    <text> 
    <link> 
     <l> 
     <dscrpt>Lesson 1 - Diet and feeding; Water and Drinking</dscrpt> 
     <hrf> diet.html </hrf> 
     </l> 

     <l> 
     <dscrpt>Lesson 2 - Feather Care </dscrpt> 
     <hrf> feather.html </hrf> 
     </l> 

     <l> 
     <dscrpt>Lesson 3 - Level three </dscrpt> 
     <hrf> item3.html </hrf> 
     </l> 

    </link> ... and so on 

.................... ........................

+3

還有就是''