var links = doc.getElementsByTagName("link");
for(var i=0; i< links.length; i++) alert(links[i]);O.o

解决方案 »

  1.   

    var items= doc.getElementsByTagName("item");
    for(var i=0; i< items.length; i++) {
       var childs=items[i].childNodes;
       if(childs!=null){
            for(var j=0;j<childs.length;j++){
                alert(childs[j].firstChild.nodeValue);
           }
       }
    }
      

  2.   

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    <!--
    function read()
    {
    var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
    var doc = new ActiveXObject("MSXML2.DOMDocument")
    doc.loadXML(str);
    var items= doc.getElementsByTagName("item");
    for(var i=0; i< items.length; i++) {
       var childs=items[i].childNodes;
       if(childs!=null){
            for(var j=0;j<childs.length;j++){
                alert(childs[j].firstChild.nodeValue);
           }
       }
    }}
    //-->
    </script>
    </head>
    <body>
    <input id="name" name="name" type="button" Value="测试" onClick="return read();">
    </body>
    </html>
    把str的定义那部分替换成你获取xml的代码那部分就可以了
      

  3.   

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    <!--
    var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
    var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll()
    {
    doc.loadXML(str);
    var items= doc.selectNodes("//item");
    var child;
    for(var i=0; i< items.length; i++) {
    childs=items[i].childNodes;
         for(var j=0;j<childs.length;j++){
                 alert(childs[j].text);
         }
    }
    }function ReadTitle(){
    doc.loadXML(str);
    var items= doc.selectNodes("//item//title");
    for(var i=0; i< items.length; i++) {
             alert(items[i].text);
    }
    }function ReadLink(){
    doc.loadXML(str);
    var items= doc.selectNodes("//item//link");
    for(var i=0; i< items.length; i++) {
             alert(items[i].text);
    }
    }
    //-->
    </script>
    </head>
    <body>
    <input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();">
    <input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();">
    <input id="name" name="name" type="button" Value="link" onClick="return ReadLink();">
    </body>
    </html>
      

  4.   

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    <!--
    var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
    function read()
    {
    var request;
    try {
    request = new XMLHttpRequest();
    }
    catch(e){
    request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    request.open("get","test.xml",false);
    request.send()
    var bob=request.responseText;
    var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll()
    {
    doc.loadXML(bob);
    var items= doc.selectNodes("//item");
    var child;
    for(var i=0; i< items.length; i++) {
    childs=items[i].childNodes;
         for(var j=0;j<childs.length;j++){
                 alert(childs[j].text);
         }
    }
    }function ReadTitle(){
    doc.loadXML(bob);
    var items= doc.selectNodes("//item//title");
    for(var i=0; i< items.length; i++) {
             alert(items[i].text);
    }
    }function ReadLink(){
    doc.loadXML(bob);
    var items= doc.selectNodes("//item//link");
    for(var i=0; i< items.length; i++) {
             alert(items[i].text);
    }
    }
    }
    //-->
    </script>
    </head>
    <body>
    <input id="name" name="name" type="button" Value="测试" onClick="return read();">
    <input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();">
    <input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();">
    <input id="name" name="name" type="button" Value="link" onClick="return ReadLink();">
    </body>
    </html>
    内部定义的没有错通过了,,但引入外部文件就出错,,,这是为什么?
      

  5.   

    var bob=request.responseText;
    好象是
    var bob=request.responseXML;
    你试一下
      

  6.   

    Text返回的是信息.xml返回的是一个对象..