Salve a tutti sono Alessandro, nuovo ma ho una richiesta super veloce e (secondo me) abbastanza complessa. Sto lavorando a un progetto che mi richiede l'utilizzo di XML, Javascript e HTML (eventualmente HTML5).
Il progetto consiste nel strutturare un file xml (che vi illustrerò di seguito) che poi verrà codificato in html tramite Javascript.
La pagina html dovrà visualizzare una tabella che contenga al suo interno vari slot e dentro ad ognuno di essi sarà presente un oggetto (un clock, un meteo, un calendario ecc.).
Il file XML è strutturato in questa maniera:
e il file HTML col JS:codice:<?xml version="1.0"?> <screen> <def> <table> <row id="1"> <column1 id="11">Colonna1</column1> <column2 id="12">Colonna2 </column2> </row> <row id="2"> <column1 id="21">Colonna1</column1> <column2 id="22"> Colonna2</column2> </row> <row id="3"> <column1 id="31">Colonna1</column1> <column2 id="32"> Colonna2</column2> </row> </table> </def> <slots> <slot id="01" > <slotitems> <slotitem1 id="001" file="clock" rowid="1" column1id="11"> -- Oggetto che dovra' essere inserito -- </slotitem1> </slotitems> </slot> </slots> </screen>
La funzione loadXML, come da nome, carica il file XML[questa funziona].codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>PROVAMIIII</title> <script language="javascript" type="text/javascript"> function loadXML(url, handler) { if ( document.implementation && document.implementation.createDocument ) { var xml = document.implementation.createDocument("", "", null); xml.onload = function() { handler(xml); } xml.load(url); } else if ( window.ActiveXObject ) { var xml = new ActiveXObject("Microsoft.XMLDOM"); xml.onreadystatechange = function() { if ( xml.readyState == 4 ) { handler(xml); } } xml.load(url); } } function popolaTabella(xml) { var table = document.getElementById("t1"); var row1 = xml.getElementsByTagName("row"); for (var i = 0; i < row1.length; i++) { var e = row1[i]; var c1 = e.getElementsByTagName("column1")[0].firstChild.data ; var c2 = e.getElementsByTagName("column2")[0].firstChild.data; function attributi(xml) { var att1 = xml.getElementByTagName("row").getAttribute("id"); e = setAttribute(id, att1); row1[i].xml.document.setAttribute("id"); } var rr = table.insertRow(i); rr.insertCell(0).appendChild(document.createTextNode(c1)); rr.insertCell(1).appendChild(document.createTextNode(c2)); } riempitab(xml); } function riempitab(xml) { var slotte = xml.getElementsByTagName("slotitem1"); document.write(slotte); } </script> </head> <body onload="javascript:loadXML('data.xml', popolaTabella);"> <table id="t1" border="4" width="100%" height="800"> </table> </body> </html>
La funzione popolaTabella, crea la struttura della tabella in base all'xml (righe e colonne ecc.)[anche questa funziona]
La funzione attributi, DOVREBBE (non capisco se lo fa o no) rilevare e settare a ogni colonna e riga l'id che presenta nell'XML
La funzione riempitab, DOVREBBE leggere i contenuti dei tag <slotitemN> e posizionarli nelle coordinate delle righe e colonne desiderate (solo che non lo fa).
Lo scopo finale sarebbe di far funzionare queste due ultime funzioni.
Grazie in anticipo.

Rispondi quotando