An ND N Documn MBDDD N NDD Documn Uu NN N Ook K
An ND N Documn MBDDD N NDD Documn Uu NN N Ook K
<html>
<head> ... </head> <body> <h1>Header</h1> <p>Text here ... </p> ... <xml id="scoreData"></xml> </body> </html>
1|Page
<table border="1" datasrc="#cdcat"> <tr> <td><span datafld="ARTIST"></span></td> <td><span datafld="TITLE"></span></td> </tr> </table> </body> </html>
The data is retrieve from the XML to be displayed in a table. In this example ARTIST and TITLE is being shown. However Firefox do not render the page the same way, as it has no support for XML Data Island.
Solution on Firefox
Possible solution to make use of XML Data Island on Firefox is to write a Javascript function to parse and render the XML data.
<html> <head> <script> varxmlDoc_modules; functionparseXML(){ varxmlNode = document.getElementById(' cdcat').innerHTML; xmlDoc_modules = loadXMLString(xmlNode); displayItems(); } functionloadXMLString(txt) { varxmlDoc; try //Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(txt); //xmlDoc.encoding="UTF-8";
2|Page
returnxmlDoc; } catch(e) { try //Firefox, Mozilla, Opera, etc. { var parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,"text/xml"); xmlDoc.encoding="UTF-8"; returnxmlDoc; } catch(e) {alert(e.message)} } return(null); }//end function loadXMLString functiondisplayItems() { vartable_str= "<br/><table border=1>"; varmodules_div = document.getElementById("div_modules"); varmodules_node=xmlDoc_modules.childNodes[0]; varlen = modules_node.childNodes.length; for (i=0; i<len ;i++) { try{ table_str = table_str + "<tr><td>"; var artist = modules_node.childNodes[i].childNodes[1].firstChild.nodeValue; table_str = table_str + artist +"</td><td>"; var title = modules_node.childNodes[i].childNodes[0].firstChild.nodeValue; table_str = table_str + title +"</td></tr>"; } catch(e){alert(e.message)} } table_str = table_str + "</table>"; modules_div.innerHTML = table_str; }//end function displayItems()
</script> </head> <body onload=parseXML();> <xml id="cdcat" style="display:none"> <catalog><cd><TITLES>Empire Burlesque</TITLES><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985< /YEAR></cd><cd><TITLES>Hide your heart</ TITLES><ARTIST>Bonnie
3|Page
</body> </html>
4|Page