xml数据岛源码,啥地方不对啊
IE XML data island:
..
<xml id= "xmldataisland ">
<foo> bar </foo>
</xml>
<SCRIPT language= "JavaScript ">
Cross-browser solution:
var xmlString = " <xml
id= "xmldataisland "> <foo> bar </foo> </xml> ";
var myDocument;
if (document.implementation.createDocument){
// Mozilla, create a new DOMParser
var parser = new DOMParser();
myDocument = parser.parseFromString(xmlString, "text/xml ");
} else if (window.ActiveXObject){
// Internet Explorer, create a new XML document using ActiveX
// and use loadXML as a DOM parser.
myDocument = new ActiveXObject( "Microsoft.XMLDOM ")
myDocument.async= "false ";
myDocument.loadXML(xmlString);
document.write(xmldom.transformNode(myDocument));
}
</SCRIPT>
ie怎么取不到 "bar "?
[解决办法]
document.write(xmldom.selectSingleNode("xml/foo"));
[解决办法]
<SCRIPT language="JavaScript"> //Cross-browser solution: var xmlString = " <xml id=\"xmldataisland\" > <foo >bar </foo > </xml >"; var myDocument; if (document.implementation.createDocument){ // Mozilla, create a new DOMParser var parser = new DOMParser(); myDocument = parser.parseFromString(xmlString, "text/xml"); } else if (window.ActiveXObject){ // Internet Explorer, create a new XML document using ActiveX // and use loadXML as a DOM parser. myDocument = new ActiveXObject("Microsoft.XMLDOM") myDocument.async="false"; myDocument.loadXML(xmlString); document.write(myDocument.selectSingleNode("xml/foo").text); } </SCRIPT>
[解决办法]
\转码
[解决办法]
var xmlString = " <xml id=\"xmldataisland\" > <foo >bar </foo > </xml >";
Javascript中引号表示字符串的头和尾如果字符串中包含有如:双引号、反斜杠、换行符、回车符等字符时就要用到转义