feed RSS
Segui buonaidea.it su YouTube Segui buonaidea.it su Twitter Segui buonaidea.it su FriendFeed Segui buonaidea.it su Facebook
| | Contattaci | Stampante | Feed RSS | Condividi questo sito nel web
Quando io ero piccolo nasce su facebook grazie ad una felice intuizione di Alberto Giarrizzo, condividere con altri i ricordi dell’infanzia...

ilmiolibro.it

Giovanni Maria Bosis


letto 12536 volte

Annie Leonard torna sull’argomento dell’impatto delle aziende sull’ambiente. Questa volta ci spiega quali sono i rischi dell’ultima trovata delle multinazionali per continuare ad inquinare facendo credere il contrario.

Annie Leonard

Annie Leonard


letto 13471 volte

» tutti i film «

visite:
1.361.028

pagine lette:
3.232.185


iscritti ai feed rss
idee

notizie

visitatori in questo momento
Ricevi i contenuti di buonaidea.it

feed RSS

Newsletter:

delivered by FeedBurner

gli onesti... i nuovi eroi!

Video: [02:07]


visto 14316 volte

Prendere il sole

audio divertente


ascoltato 26720 volte

» tutti audio «
I gatti romani

barzelletta


letta 18711 volte

ASP e XML: funzioni base per inserire, modificare e eliminare dati

Translate this page:
del 20/09/2007 | da redazione | idea letta 9831 volte
Foto dell'Idea
Per chi programma, spesso è necessario immagazzinare le informazioni in un database XML, in modo da poter gestire meglio i dati in esso contenuti.
In questo articolo spiegheremo come manipolarli utilizzando VBScript, il linguaggio delle pagine ASP.

Nell'esempio utilizzeremo il seguente database XML, posto in una cartella con diritti di lettura e scrittura:

<?xml version='1.0' encoding='iso-8859-1'?>
<root>
<record>
<id>1</id>
<nome>Andrea</nome>
<cognome>Rossi</cognome>
</record>
<record>
<id>2</id>
<nome>Valeria</nome>
<cognome>Bianchi</cognome>
</record>
<id>3</id>
<nome>Francesca</nome>
<cognome>Marroni</cognome>
</record>
</root>

Vediamo ora come fare per INSERIRE un record:

<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = True

Dim xmlHttp
Dim xmlDoc
Dim xmlUrl
Dim oldnode
Dim newnode xmlUrl="http://www.miosito.it/public/database.xml"

set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "get",xmlUrl, false
xmlHttp.send()

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.Load(xmlHttp.responseXML)

if xmlDoc.parseError.errorcode<>0 then
response.write("Errore!")
else
set newnode = xmlDoc.createElement("record")
newnode.appendChild(xmlDoc.createElement("id"))
newnode.childnodes(0).text = "4"
newnode.appendChild(xmlDoc.createElement("Nome"))
newnode.childnodes(1).text = "Marco"
newnode.appendChild(xmlDoc.createElement("Cognome"))
newnode.childnodes(2).text = "Arancioni"
xmlDoc.documentElement.appendChild(newnode.cloneNode (true))
xmlDoc.Save("D:\Inetpub\webs\miosito\public\database.xml")
end if

Set oldnode= nothing
Set newnode= nothing
Set xmlDoc= nothing
Set xmlHttp= nothing

%>


Vediamo ora come fare per MODIFICARE un record:

<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = True

Dim xmlHttp
Dim xmlDoc
Dim xmlUrl
Dim node
Dim record

xmlUrl="http://www.miosito.it/public/database.xml"

set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "get",xmlUrl, false
xmlHttp.send()

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.Load(xmlHttp.responseXML)
if xmlDoc.parseError.errorcode<>0 then
response.write("Errore!")
else
set node = xmlDoc.documentElement.selectSingleNode("//root/record[id='3']")
For Each record In node.childNodes
Select Case record.nodeName
Case "id"
record.firstChild.nodevalue = "5"
Case "Nome"
record.firstChild.nodevalue = "Marco"
Case "Cognome"
record.firstChild.nodevalue = "Rossi"
End Select
Next
xmlDoc.Save("D:\Inetpub\webs\miosito\public\database.xml") end if
Set node= nothing
Set xmlDoc= nothing
Set xmlHttp= nothing

%>


Vediamo ora come fare per ELIMINARE un record:

<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = True

Dim xmlHttp
Dim xmlDoc
Dim xmlUrl
Dim record xmlUrl="http://www.miosito.it/public/database.xml"

set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "get",xmlUrl, false
xmlHttp.send()

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.Load(xmlHttp.responseXML)
if xmlDoc.parseError.errorcode<>0 then
response.write("Errore!")
else
set record = xmlDoc.documentElement.selectSingleNode("//root/record[id='3']")
xmlDoc.documentElement.removeChild(record)
xmlDoc.Save("D:\Inetpub\webs\miosito\public\database.xml")
end if
Set record= nothing
Set xmlDoc= nothing
Set xmlHttp= nothing

%>

Tags: computer programmazione

"Ti è piaciuto questo articolo? Se vuoi, puoi ricevere gratuitamente sul tuo PC i nostri contenuti, attraverso la pagina dei feed di buonaidea.it"

Idee interessanti per te

Translate this page: 

RICERCA NEL SITO:

NOTA:
Inserisci nella casella le parole chiave e premi "Cerca".


X
Invia e-mail