Salve a tutti
è possibile, dato un file xml in input , utilizzando asp importare i dati contenuti nel file in un db?
ho fatto una ricerca ma non ho trovato nulla di esplicativo
Grazie
Salve a tutti
è possibile, dato un file xml in input , utilizzando asp importare i dati contenuti nel file in un db?
ho fatto una ricerca ma non ho trovato nulla di esplicativo
Grazie
Cerca esempi su Microsoft.XMLDOM object
Con i metodi selectNodes e selectSingleNode peschi i valori dei nodi e costruisci un insert con i valori
Ok grazie lo sto usando....
ora però ho un problema...
E così funziona benissimo!codice:Dim xmlDom, nodo, i set xmlDom = Server.CreateObject("Microsoft.XMLDOM") xmlDom.async = false xmlDom.Load(Server.MapPath("fileProva.xml")) Set nodo= xmldom.getElementsByTagName("record") Response.Write("Primo valore = " & nodo(0).selectSingleNode("primoValore").Text & " ") Response.Write("Secondo valore = " & nodo(0).selectSingleNode("secondoValore").Text & " ") Set nodo = Nothing Set xmlDom = Nothing
Però non riesco a ciclare nei nodi....
Ho fatto questo tentativo:
Ma mi da errore..codice:for i = 0 To 4 Response.Write("Primo valore = " & nodo(i).selectSingleNode("primoValore").Text & " ") Response.Write("Secondo valore = " & nodo(i).selectSingleNode("secondoValore").Text & " ") Next
che sbaglio?codice:Errore di run-time di Microsoft VBScript (0x800A01A8) Necessario oggetto: '[object]' /importxml/letturaVbScript.asp, line 13
risolto posto il codice
ad uso del forum
codice:Dim xmlDom, nodo, i set xmlDom = Server.CreateObject("Microsoft.XMLDOM") xmlDom.async = false xmlDom.Load(Server.MapPath("fileProva.xml")) Set nodo= xmldom.getElementsByTagName("record") for i = 0 To nodo.Length - 1 Response.Write("Primo valore = " & nodo(i).selectSingleNode("primoValore").Text & " ") Response.Write("Secondo valore = " & nodo(i).selectSingleNode("secondoValore").Text & " ") Next Set nodo = Nothing Set xmlDom = Nothing
Ancora un problem ain questa importazione...
Se ho un nodo del genere:
lo 0 lo recupero concodice:<RATING Country="ITA">0</RATING>
Ma come si fa a recuperare il valore di Country?codice:<%=nodo(i).selectSingleNode("RATING").Text%>
Grazie
accedi alla proprieta attributes
un esempio semplice esplicativo
XML
LETTURAcodice:<RECORD> <RATING Country="ITA">0</RATING> <RATING Country="ENG">1</RATING> <RATING Country="FRA">0</RATING> <RATING Country="TED">1</RATING> </RECORD>
OUTPUTcodice:<% Dim xmlDom, nodo, i set xmlDom = Server.CreateObject("Microsoft.XMLDOM") xmlDom.async = false xmlDom.Load(Server.MapPath("test.xml")) Set nodo= xmldom.documentElement.childNodes Dim att for each elm in nodo Response.write("nome attributo = " & elm.attributes.item(0).name & "") Response.write("valore attributo = " & elm.attributes.item(0).text & "") Response.Write("VALORE NODO = " & elm.Text & " ") Next Set nodo = Nothing Set xmlDom = Nothing %>
in attributes.item(0).name trovi il nome del primo attributocodice:nome attributo = Country valore attributo = ITA VALORE NODO = 0 nome attributo = Country valore attributo = ENG VALORE NODO = 1 nome attributo = Country valore attributo = FRA VALORE NODO = 0 nome attributo = Country valore attributo = TED VALORE NODO = 1
logicamente come in un array, in item(1) l'eventuale secondo attributo item(2) l'eventuale 3° attributo etc etc
Ok sono alle prese con l'ennesiomo problema di questa divolo di importazione...
A sto punto credo e spero che possa essere l'ultimo...
mi leggo sto cacchio di file così:
E va benissimocodice:<%@LANGUAGE ="VBSCRIPT"%> <%option explicit%> <html> <head> <title>Recupero Dati da XML file</title> <link href="fogliDiStile/style.css" rel="stylesheet" type="text/css"> </head> <body> <table cellpadding="0" cellspacing="0" border="1" width="200%"> <tr class="verdanaBlu11Bold" align="center"> <td>N°</td> <td>Event Id</td> <td>Start Date</td> <td>Start Time</td> <td>Duration</td> <td>EPG</td> <td>EPG Name</td> <td>EPG Sinopsi</td> <td>EPG Log Line</td> <td>Theme</td> <td>Rating</td> <td>Rating Country</td> <td>Product</td> <td>Buy Window</td> </tr> <% Dim xmlDom, nodoEvento, ne, nodoStart, nodoEpgSect, nodoEpg, nodoEpgRat, nodoAccess, nodoIppvSect set xmlDom = Server.CreateObject("Microsoft.XMLDOM") xmlDom.async = false xmlDom.Load(Server.MapPath("file.xml")) Set nodoEvento = xmldom.getElementsByTagName("EVENT_SECTION") Set nodoStart = xmldom.getElementsByTagName("START") Set nodoEpgSect = xmldom.getElementsByTagName("EPG_SECTION") Set nodoEpg = xmldom.getElementsByTagName("EPG") Set nodoEpgRat = xmldom.getElementsByTagName("RATING") Set nodoAccess = xmldom.getElementsByTagName("CA_SECTION") Set nodoIppvSect = xmldom.getElementsByTagName("IPPV_SECTION") For ne = 0 To nodoEvento.Length - 1 %> <tr class="verdanaBlu11" align="center"> <td><%=ne%></td> <td><%=nodoEvento(ne).selectSingleNode("EVENTID").Text%></td> <td><%=nodoStart(ne).selectSingleNode("DATE").Text%></td> <td><%=nodoStart(ne).selectSingleNode("TIME").Text%></td> <td><%=nodoEpgSect(ne).selectSingleNode("DURATION").Text%></td> <td><%=nodoEpg(ne).attributes.item(0).Name%> = <%=nodoEpg(ne).attributes.item(0).Value%></td> <td><%=nodoEpg(ne).selectSingleNode("NAME").Text%></td> <td><%=nodoEpg(ne).selectSingleNode("SYNOPSIS").Text%></td> <td><%=nodoEpg(ne).selectSingleNode("LOG_LINE").Text%></td> <td><%=nodoEpgSect(ne).selectSingleNode("THEME").Text%></td> <td><%=nodoEpgSect(ne).selectSingleNode("RATING").Text%></td> <td><%=nodoEpgRat(ne).attributes.item(0).Name%> = <%=nodoEpgRat(ne).attributes.item(0).Value%></td> <td><%=nodoAccess(ne).Text%></td> <td><%=nodoIppvSect(ne).selectSingleNode("BUYWINDOW").Text%></td> </tr> <% Next Set nodoIppvSect = Nothing Set nodoAccess = Nothing Set nodoEpgRat = Nothing Set nodoEpg = Nothing Set nodoEpgSect = Nothing Set nodoStart = Nothing Set nodoEvento = Nothing Set xmlDom = Nothing %> </table> </body> </html>
Il problema è che alcuni nodi non sempre ci sono ad esempio l'ultimo che leggo è opzionale.
CHiaramente il ciclo mi va in errore se si verifica sta cosa.
Come posso intercettarla?
Ho provato con cose tipo
ocodice:If Is Null(nodoIppvSect(ne)) then
Ma non mi si fila e neanche se acodice:If nodoIppvSect(ne) = "" then
Aggiungocodice:nodoIppvSect(ne)
Nelle If...codice:nodoIppvSect(ne).selectSingleNode("BUYWINDOW").Text
Come caspita si fa sta cosa?
![]()
prova con
ocodice:if TypeName(nodoIppvSect(ne)) <> "Nothing" then
codice:if varType(nodoIppvSect(ne)) <> 9 then