用javascript访问XML中的CDATA区内容: <script> 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> |
|