eccomi con i miei primi problemi di cross-browser compatibility (ovviamente sono indietro con la schedule perché tutti i tutorial che volevo fare avevano tutorial prerequisiti, ma la notte è giovane).
xPath, bel linguaggio di navigazione in XML, è implementato MOLTO diversamente in IE e in Mozilla&co.
per selezionare una lista di nodi:
xmlDoc.selectNodes(path expression) in IE
in Firefox bisogna fare un oggetto XPathEvaluator: dal sito http://www.wrox.com/WileyCDA/Section/id-291861.html
This example uses the XPathResult.ORDERED_NODE_ITERATOR_TYPE result, which is the most commonly used result type. If no nodes match the XPath expression, evaluate() returns null; otherwise, it returns an XPathResult object. If the result is a node iterator, whether it be ordered or unordered, you use the iterateNext() method repeatedly to retrieve each matching node in the result. When there are no further matching nodes, iterateNext() returns null.
var oEvaluator = new XPathEvaluator();
var oResult = oEvaluator.evaluate("employee/name",
oXmlDom.documentElement, null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
if (oResult != null) {
var oElement = oResult.iterateNext();
while(oElement) {
alert(oElement.tagName);
oElement = oResult.iterateNext();
}
}
L'articolo continua spiegando che si possono fare funzioni aggiuntive per Element per poter usare la stessa sintassi. E' un po'complicato though, speriamo che non serva - in mancanza di tempo vado avanti tenendo buona la referenza.
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento