Ho questo script javascript:
che dovrebbe stamparmi il contenuto del documento caricato in loadXMLDoc, prima riga verde.codice:<script type="text/javascript"> function loadXMLDoc(fname) { var xmlDoc; if (window.ActiveXObject) { // Internet Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else if (document.implementation && document.implementation.createDocument) { // altri browser xmlDoc=document.implementation.createDocument("","",null); } else { alert('Non puoi utilizzare questo script!!!'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } /* funzione per utilizzare filtri XPath*/ function myPath(xml, path) { var array = new Array(); if (window.ActiveXObject) // Internet Explorer { xml.setProperty("SelectionLanguage","XPath"); var nodes=xml.selectNodes(path); for (i=0;i<nodes.length;i++) { array[i] = nodes[i].childNodes[0].nodeValue; } } // Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { var nodes=document.evaluate(path, xml, null, XPathResult.ANY_TYPE,null); var result=nodes.iterateNext(); var j=0; while (result) { array[j] = result.childNodes[0].nodeValue; result=nodes.iterateNext(); j++; } } return array; } var xml = loadXMLDoc("rubriche.xml"); titolo = myPath(xml, "/html/head/title"); document.write(titolo); </script>
Il documento ha questo formato:
Premettendo che so che non è XHTML valido ne tantomeno XML valido, la mia domanda è un altra. Perchè se questo codice lo salvo come rubriche.xml mi ritorna il contenuto di title, mentre se questo stesso testo lo salvo come rubriche.html non mi viene stampato nulla???codice:<html> <head> <title>questo è un titolo</title> </head> </html>

Rispondi quotando