js 读取xml文件

读取xml文件 [原创 2007-6-20 17:35:37]   
我顶 字号:  

js中读取xml文件,简单的例子:

<html>
<head>
<script>
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("b.xml")
var nodes=xmlDoc.documentElement.childNodes;
for(var i=0;i<nodes.length;i++){
 alert(nodes[i].getAttribute("text")); 
}
</script>
</head>
</html>

----------------------------------------

b.xml文件如下:

<?xml version="1.0" encoding="GB2312"?>
 <xmlmenu>
    <menu id='1' icon='r_heart.gif' text='招商状态评估'  title='w'></menu>
    <menu id='2' icon='r_heart.gif' text='工作计划及总结'  title='w'></menu>
    <menu id='3' icon='r_heart.gif' text='系统维护' title=''></menu>
    <menu id='4' icon='r_heart.gif' text='内部论坛' title=''></menu>
    <menu id='5' icon='r_heart.gif' text='系统公告' title=''></menu>
    </xmlmenu>

posted on 2014-06-01 19:09  Lishenyin  阅读(241)  评论(0编辑  收藏  举报

导航