2013-04-17 55 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

还有就是''