/////////////////*  temp.xml文件  //////////////////
<?xml version="1.0" encoding="GBK"?>
<a>
   <!--定义循环项目,内写属性.-->
   <b Attribute1="hi" text="1"/>
   <b Attribute1="我是谁呀..." text="2"/>
</a>
/////////////* htm文件 *////////////
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>selectNodes</title>
</head>
<body>
<script> 
var xmldom = new ActiveXObject("Microsoft.XMLDOM");
xmldom.async = false;  
var url="temp.xml"; 
xmldom.load(url); 
var str=""; 
//获取所有相关的子节点
var nodes=xmldom.documentElement.selectNodes("//a/b"); 
for(j=0;j<nodes.length;j++) 
{
//.getAttribute 方法为获取节点的属性
     str += "<div>"+ nodes[j].getAttribute("text") +" - "+ nodes[j].getAttribute("Attribute1") +"</div>";
}
document.write(str); 
//window.open("qh309.htm", "", "fullscreen");  
</script>
</body>
</html>

解决方案 »

  1.   

    var nodes=xmldom.selectSingleNode("//NodeName/@属性").value;
      

  2.   

    对啦,孟子E章:
    var url="../../Web.config"; 不行,如果我将Web.config改名为Web.xml就行?怎么回事?
    还有,孟子你的只能得到第一个<add>节点的值。
    <script language="javascript">
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    var url="../../Web.config"; 
    xmlDoc.load(url);
    var str="获取所有相关的子节点"; 
    //获取所有相关的子节点
    var nodes=xmlDoc.documentElement.selectNodes("//configuration/appSettings/add"); 
    for(j=0;j<nodes.length;j++) 
    {
    if(nodes[j].getAttribute("key")=="SystemMessage")
    str=nodes[j].getAttribute("value");
    }
    //下面的语句只能选择第一个符合节点的值。
    //var nodes=xmlDoc.selectSingleNode("//configuration/appSettings/add/@value").value;
    document.write(str); 
    </script>
      

  3.   

    大哥........你的xml文件编码有问题呀.....
    应是encoding="gb2312"
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 2</title>
    </head>
    <body><table height="30" width="100%" border="0">
    <tr><td>
    <MARQUEE id="sys_bulletin" onmouseover="this.stop()" onmouseout="this.start();" scrollAmount="5" direction="left" behavior="scroll" loop="0" runat="server">

    <script> 
    var xmldom = new ActiveXObject("Microsoft.XMLDOM");
    xmldom.async = false;  
    var url="temp2.xml"; 
    xmldom.load(url); 
    var str=""; 
    var nodes=xmldom.documentElement.selectNodes("//configuration/appSettings/add"); 
    for(j=0;j<nodes.length;j++) 
    {
         str += "<div>"+ nodes[j].getAttribute("value") +" - "+ nodes[j].getAttribute("key") +"</div>";
    }
    document.write(str); 
    </script>
    </MARQUEE>
    </td></tr>
    </table></body>
    </html>
      

  4.   

    只选一个地如下<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 2</title>
    </head>
    <body><table height="30" width="100%" border="0">
    <tr><td>
    <MARQUEE id="sys_bulletin" onmouseover="this.stop()" onmouseout="this.start();" scrollAmount="5" direction="left" behavior="scroll" loop="0" runat="server">
    <script> 
    var xmldom = new ActiveXObject("Microsoft.XMLDOM");
    xmldom.async = false;  
    var url="temp2.xml"; 
    xmldom.load(url); 
    var str=""; 
    var nodes=xmldom.documentElement.selectSingleNode("//configuration/appSettings/add"); 
    str =  nodes.getAttribute("value") ;
    document.write("请在分辨率为1024*768下使用.");
    document.write(str); 
    </script>
    </MARQUEE>
    </td></tr>
    </table>
    </body>
    </html>
      

  5.   

    <add key="ConnectionString" value="server=localhost;DataBase=www_yueyan_com;uid=sa;pwd=sa" />
    <add key="SystemMessage" value=" 本站消息:现阶段提供主页栏码共享!" />楼上的:
    我是想用孟子E章的一句话就得到内容:
    xmldom.selectSingleNode("//NodeName/@属性").value;
    可是我这样写:xmlDoc.selectSingleNode("//configuration/appSettings/add/@value").value;得到的是第一个add节点的值,我想利用这类似的一句话得到第二个的值。
      

  6.   

    xmlDoc.selectSingleNode("(//configuration/appSettings/add/@value)[2]").value
      

  7.   

    你的iis设置里禁止访问.config的