日期:2014-05-16  浏览次数:20468 次

js解析xml文件完整实例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JS读取XMLDemo</title>

    <script language="javascript" type="text/javascript">
        function NewInfoAction()
        {
            var dom;
            var type=1;                                         //默认为IE浏览器
            var data = new Array();                             //存储实体的数组 
        
            if(navigator.userAgent.indexOf("MSIE")>0)
            {
                dom = new ActiveXObject("Microsoft.XMLDOM");    //实例化dom对象
                /*
                    这个地方很多朋友不明白,我写详细点
                    设置异步处理
                    本函数不需要在XML文件读取完成之前进行任何操作,
                    因此关闭异步处理功能。
                */
                dom.async = false;                           
                dom.load("NewInfo.xml");                        //加载xml文件
                window.alert('IE');
            }
            else if(isFirefox=navigator.userAgent.indexOf("Firefox") > 0)
            {
                type=2;
                dom = document.implementation.createDocument("", "", null);         //火狐不支持ActiveXObject
                dom.async = false;
                dom.load("NewInfo.xml");