Ciao a tutti,
voglio implementare sul mio sito un servizio di meteo estraendo dei dati che mi vengono forniti in xml nella mia pagina asp.
il mio probmlema è che negli XML che mi forniscono ci sono dei nodi e dei "sottonodi" e non riesco ad interrogare correttamente i dati:
il file xml è composto così:
<information city="Caorle" id="1272">
<day value="28.03.2007">
<hour value="00:00 a">
<temp>9.76</temp>
<description>8</description>
<precipitation>0.00</precipitation>
</hour>
<hour value="03:00 a">
<temp>6.04</temp>
<description>8</description>
<precipitation>0.00</precipitation>
</hour>
[...]
</day>
<day value="29.03.2007">
<hour value="00:00 b">
<temp>9.76</temp>
<description>8</description>
<precipitation>0.00</precipitation>
</hour>
<hour value="03:00 b">
<temp>6.04</temp>
<description>8</description>
<precipitation>0.00</precipitation>
</hour>
[...]
</day>
[...]
</information>
Per interrogarlo ho questo codice asp:
<%
' connessione al file XML
Dim objXMLHTTP
Dim objXmlDom
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
Set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
objXmlDom.async = False
StrURL = "http://www.miosito.it/meto.xml"
objXMLHTTP.Open "GET", StrURL, false
objXmlHTTP.send("")
objXmlDom.loadXML(objXMLHTTP.ResponseText)
If objXmlDom.parseError.errorCode <> 0 Then
Response.Write(objXmlDom.parseError.reason)
Response.Write(objXmlDom.parseError.errorCode)
Response.End
End If
Set AllItems = objXmlDom.selectNodes("//day")
Set AllItemsH = objXmlDom.selectNodes("//hour")
Set Giorno = objXmlDom.selectNodes("//day")
Set Img = objXmlDom.getElementsByTagName ("information/day/hour/description")
Set Temp = objXmlDom.getElementsByTagName ("information/day/hour/temp")
Set Prec = objXmlDom.getElementsByTagName ("information/day/hour/precipitation")
' Ciclo per la stampa a video dei dati
For I = 0 to (Giorno.Length - 1)
Response.Write("
" & Giorno(I).GetAttribute("value") & "
")
Set Ora = objXmlDom.selectNodes("//day/hour")
For u = 0 To Ora.length - 1
Response.Write("" & Ora(u).GetAttribute("value") & "
")
next
set Ora = nothing
Next
Set Giorno = nothing
%>
il problema sta nel ciclo, infatti con la sola parte:
<%
For I = 0 to (Giorno.Length - 1)
Response.Write("
" & Giorno(I).GetAttribute("value") & "
")
Next
%>
mi scrive tutte le date presenti nell'XML... fin qui quindi tutto ok!!
il problema nasce quando voglio estrarre il secondo nodo, quello con le ore:
<%
Set Ora = objXmlDom.selectNodes("//day/hour")
For u = 0 To Ora.length - 1
Response.Write("" & Ora(u).GetAttribute("value") & "
")
next
set Ora = nothing
%>
così facendo infatti mi vengono stampate tutte le ore sotto ogni giorno, quindi il risultato con l'XML e il codice ASP che avete visto sarà questo:
28.03.2007
00.00 a
03.00 a
00.00 b
03.00 b
29.03.2007
00.00 a
03.00 a
00.00 b
03.00 b
invece quello di cui ho bisogno è che il risultato sia:
28.03.2007
00.00 a
03.00 a
29.03.2007
00.00 b
03.00 b
VI PREGO AIUTATEMI!!!![]()

Rispondi quotando
:master:
