JS编写XMl

  function load() {

            var xmldom;

            var student = "<?xml version='1.0' encoding='utf-8'?><classes><class>.NET19班</class><class>.NET20班</class></classes>";

//判断是否是IE浏览器

            if (window.DOMParser) {//不是IE

 

                var parser = new DOMParser();

                xmldom = parser.parseFromString(student, "text/xml");

                var divmsg = document.getElementById("msg");

                //获取节点对象

                var nodes = xmldom.documentElement.getElementsByTagName("class");

                for (var i = 0; i < nodes.length; i++) {

                    divmsg.innerHTML += nodes[i].childNodes[0].data + "<br />";

                }

            }

            else {//是IE

                xmldom = new ActiveXObject("Microsoft.XMLDOM");

                xmldom.async = false;

                xmldom.load("WriterClasses.xml");

                var divmsg = document.getElementById("msg");

              //获取节点对象

                var nodes = xmldom.documentElement.getElementsByTagName("class");

                for (var i = 0; i < nodes.length; i++) {

                    divmsg.innerHTML += nodes[i].childNodes[0].text + "<br />";

                }

            }

        }

posted @ 2013-04-16 23:59  幸福的娟娟  阅读(320)  评论(0编辑  收藏  举报