两段demo代码如下(for ie only): <script type="text/javascript"> //demo1 var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); var root; var CDATASection; xmlDoc.async = false; xmlDoc.loadXML("<a/>"); root = xmlDoc.documentElement; CDATASection = xmlDoc.createCDATASection("Hello World!"); root.appendChild(CDATASection); b=xmlDoc.createElement("Test") b.text="hahahahaha" root.appendChild(b); alert(root.xml); for(i =0;i<root.childNodes.length;i++) { if(root.childNodes[i].nodeType==4) alert(root.childNodes[i].nodeValue) } </script>
<script type="text/javascript"> //demo2 var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); xmlDoc.async = false; xmlDoc.loadXML("<a><![CDATA[aaaaaaaaaaaaaaaaaaaaa]]></a>"); root = xmlDoc.documentElement; for(i =0;i<root.childNodes.length;i++) { if(root.childNodes[i].nodeType==4) alert(root.childNodes[i].nodeValue) } </script> //demo3( for firefox) <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > < HTML > < HEAD > < TITLE > 使firefox对xml的处理兼容IE的selectSingleNode selectNodes方法 </ TITLE > < META NAME ="Author" CONTENT ="emu" > < META NAME ="Keywords" CONTENT ="firefox IE selectSingleNode selectNodes" > < META NAME ="Description" CONTENT ="使firefox可以支持selectSingleNode selectNodes方法" > < SCRIPT LANGUAGE ="JavaScript" > <!-- var isIE = !! document.all;
function parseXML(st){ if (isIE){ var result = new ActiveXObject( " microsoft.XMLDOM " ); result.loadXML(st); } else { var parser = new DOMParser();