Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 14 su 14

Discussione: scrivere su file xml

  1. #11
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    ho un grosso problema
    codice:
    <%
    
    strFile = "nome.asp"							'il nome di questo file
    strTable = "nome"											'nome tabella
    strKey = "ID"													'chiave primaria, contatore
    bgHeaderColor = "Orange"					
    fontHeaderColor = "black"			
    bgColor1 = "Silver"						
    fontColor1 = "Black"					
    bgColor2 = "White"						
    fontColor2 = "Black"					
    
    
    Set MyConn=Server.CreateObject("ADODB.Connection")
    MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("/mdb-database/database2.mdb")
    
    
    
    '**************************************
    'azioni da eseguire
    '**************************************
    Select Case Request("mode")
    	Case "AddItem"
    		AddItem
    	Case "AddItemAction"
    		AddItemAction
    	Case "EditItem"
    		EditItem
    	Case "EditItemAction"
    		EditItemAction
    	Case "DelItem"
    		delItem
    	Case Else
    		ShowAll
    End Select
    
    
    
    
    '**************************************
    'mostrare tutti i record
    'FORTEMENTE SCONSIGLIATO PER I DATABASE DI GRANDE DIMENSIONE
    '**************************************
    Sub ShowAll()
    
    	MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	
    	Response.write ("<h2> Tabella " & strTable & ":</h2>")
    	Response.write ("<table border=""1"" cellpadding=""4"" cellspacing=""1"">")
    	Response.write ("<tr>")
    	
    	numerocampi=MyRs.fields.count -1
    			
    	Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" nowrap><font color=""" & fontHeaderColor & """ size=""2"">E</font></td>")
    	
    	for i=0 to numerocampi 
    		if Not MyRs(i).name = "ID" then
    			Response.write ("<td bgcolor=""" & bgHeaderColor & """ align=""Center"" nowrap><font color=""" & fontHeaderColor & """ size=""2"">" & MyRs(i).name & "</font></td>")
    		end if
    	next 
    	
    	Response.write ("</tr>")
    	
    	do while not MyRs.eof 
    	
    	if bgColor = bgColor2 then
    		bgColor = bgColor1
    		fontColor = fontColor1
    	else
    		bgColor = bgColor2 
    		fontColor = fontColor2
    	end if
    	
    	Response.write ("<tr>")
    	Response.write ("<td align=""Center"" valign=""Top"" bgcolor=""" & bgColor & """>")
    	Response.write ("<font color=""" & fontColor & """>Modifica</font></td>")
    	
    	for i = 0 to numerocampi
    		if Not MyRs(i).name = "ID" then
    			if MyRs(i).name = "PRICE" then
    				ThisRecord = FormatCurrency(MyRs(i))
    				strAlign = "right"
    			else
    				ThisRecord = MyRs(i)
    				strAlign = ""
    			end if
    			If IsNull(ThisRecord) or ThisRecord = "" Then
    				ThisRecord = ""
    			end if 
    			ThisRecord  = Replace(ThisRecord,vbCrLf,"
    ")
    			Response.write ("<td width=""500px"" height=""auto"" align=""" & strAlign & """ valign=top bgcolor=""" & bgColor & """><font color=""" & fontColor & """>" & Thisrecord & "</font></td>")
    		end if
    	next 
    	
    	Response.write ("</tr>")
    	
    	MyRs.movenext
    	loop
    	
    	Response.write ("</table>")
    	
    	MyRs.close
    	Set MyRs= Nothing
    	
    end sub
    
    
    
    '**************************************
    'modificare
    '**************************************
    Sub EditItem()
    
    	Response.write ("<h2>Modifica record nella tabella " & strTable & ":</h2>")
    	
    	which=request("which")
    	
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    	Set MyRs=MyConn.Execute(MySQL)
    
    	Response.write ("<FORM ACTION=""" & strFile & "?mode=EditItemAction"" METHOD=POST>")
    	Response.write ("<input name=""ID"" type=""hidden"" value=""" & MyRs(strKey) & """>")
    	Response.write ("<table>")
    
    	numerocampi=MyRs.fields.count -1
    	
    	for i=0 to numerocampi
    	
    	if Not MyRs(i).name = "ID" then
    		ThisRecord = MyRs(i)
    		ThisRecordName = MyRs(i).name
    		If IsNull(ThisRecord) or ThisRecord = "" Then
    			ThisRecord = ""
    		end if 
    	Response.write ("<tr>")
    	Response.write ("<td height =""auto"" align=""right"">" & ThisRecordName & ": </td>")
    	Response.write ("<td> <TEXTAREA name=""" & ThisRecordName & """ rows=""10"" cols=""60"" value=""" & MyRs(i) & """>" & Thisrecord & "</TEXTAREA></td>")
    	Response.write ("</tr>")
    	end if
    	next
    
    	Response.write ("<tr>")
    	Response.write ("<td align=""right""><INPUT NAME=""Submit"" TYPE=Submit Value=""Aggiorna""></td>")
    	Response.write ("</tr>")
    	Response.write ("</table>")
    	Response.write ("</FORM>")
    
    	Response.write ("Torna alla lista dei record")
    		
    	MyRs.close
    	Set MyRs= Nothing
    
    End Sub
    
    
    Sub EditItemAction()
    
    	which = Request(strKey)
    	
    	if isNumeric(which) then
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = " & which
    	else
    		MySQL="SELECT * FROM " & strTable & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL="Select * from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    
    	numerocampi=MyRs.fields.count -1
    
    	for i=0 to numerocampi
    		if Not MyRs(i).name = "ID" then	
    			str = MyRs(i).name 
    			strNames = Request(str)
    			strNames = replace(strnames,"'","''")
                if not i = numerocampi then
    				str1 = str1 & "[" & str & "] = '" & strNames & "', "
    			else
    				str1 = str1 & "[" & str & "] = '" & strNames & "'"
    			end if
    		end if
    	next
    
    	if isNumeric(which) then
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = " & which
    	else
    		MySQL1="UPDATE " & strTable & " SET " & str1 & " Where " & strKey & " = '" & which & "'"
    	end if
    
    	'MySQL1="UPDATE " & strTable & " SET " & str1 & " Where ID=" & which
    
    	Set MyRs1=MyConn.Execute(MySQL1)
    	
    	
        MySQL="Select bio from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	 
    	
    	dim bio
    	bio = MyRs("bio")
    
    'Inizializzo le Variabili 
    Dim xmlDoc, root 
    Dim xmlContent, success 
    Dim xmlData 
    Dim i 
    
    'Creo l' oggetto MsXML2.DOMDocument 
    Set xmlDoc = Server.CreateObject("msxml2.DOMDocument") 
    
    'Creo il Documento XML 
    xmlContent = "<menu>"
    xmlContent = xmlContent & "<item>" 
    xmlContent = xmlContent & "<titolo></titolo>" 
    xmlContent = xmlContent & "<testo>" & bio & "</testo>"  
    xmlContent = xmlContent & "</item>"
    xmlContent = xmlContent & "</menu>" 
    'Fine Creazione XML 
    
    'Controllo se il File XML sia stato caricato Correttamente 
    success = xmlDoc.loadXML(xmlContent) 
    If success = True Then 
         'Visualizzo tutti i dati nel File XML 
         set xmlData = xmlDoc.getElementsByTagName("menu/item/titolo/testo") 
         For i = 0 To (xmlData.length - 1) 
              Response.Write "[*]" & xmlData.Item(i).xml 
         Next 
         set xmlData = nothing 
         'Fine visualizzazione 
    Else 
         Response.Write "Impossibile caricare il File XMl... " & Server.HTMLEncode(xmlContent) 
    End If 
    
    'Salviamo il File XML 
    xmlDoc.save Server.Mappath("/public/nomebio.xml") 
    
    'Pulizia degli oggetti 
    Set xmlDoc = Nothing
    
    MySQL="Select news from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	 
    	
    	dim news
    	news = MyRs("news")
    
    'Inizializzo le Variabili 
    Dim xmlDoc2, root2 
    Dim xmlContent2, success2 
    Dim xmlData2 
    Dim i2 
    
    'Creo l' oggetto MsXML2.DOMDocument 
    Set xmlDoc2 = Server.CreateObject("msxml2.DOMDocument") 
    
    'Creo il Documento XML 
    xmlContent2 = "<menu>"
    xmlContent2 = xmlContent2 & "<item>" 
    xmlContent2 = xmlContent2 & "<titolo></titolo>" 
    xmlContent2 = xmlContent2 & "<testo>" & news & "</testo>"  
    xmlContent2 = xmlContent2 & "</item>"
    xmlContent2 = xmlContent2 & "</menu>" 
    'Fine Creazione XML 
    
    'Controllo se il File XML sia stato caricato Correttamente 
    success2 = xmlDoc2.loadXML(xmlContent2) 
    If success2 = True Then 
         'Visualizzo tutti i dati nel File XML 
         set xmlData2 = xmlDoc2.getElementsByTagName("menu/item/titolo/testo") 
         For i2 = 0 To (xmlData2.length - 1) 
              Response.Write "[*]" & xmlData2.Item(i2).xml 
         Next 
         set xmlData2 = nothing 
         'Fine visualizzazione 
    Else 
         Response.Write "Impossibile caricare il File XMl... " & Server.HTMLEncode(xmlContent2) 
    End If 
    
    'Salviamo il File XML 
    xmlDoc2.save Server.Mappath("/public/nomenews.xml") 
    
    'Pulizia degli oggetti 
    Set xmlDoc2 = Nothing
        
        MySQL="Select productions from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	 
    	
    	dim productions
    	productions = MyRs("productions")
    
    'Inizializzo le Variabili 
    Dim xmlDoc3, root3 
    Dim xmlContent3, success3
    Dim xmlData3 
    Dim i3 
    
    'Creo l' oggetto MsXML2.DOMDocument 
    Set xmlDoc3 = Server.CreateObject("msxml2.DOMDocument") 
    
    'Creo il Documento XML 
    xmlContent3 = "<menu>"
    xmlContent3 = xmlContent3 & "<item>" 
    xmlContent3 = xmlContent3 & "<titolo></titolo>" 
    xmlContent3 = xmlContent3 & "<testo>" & productions & "</testo>"  
    xmlContent3 = xmlContent3 & "</item>"
    xmlContent3 = xmlContent3 & "</menu>" 
    'Fine Creazione XML 
    
    'Controllo se il File XML sia stato caricato Correttamente 
    success3 = xmlDoc3.loadXML(xmlContent3) 
    If success3 = True Then 
         'Visualizzo tutti i dati nel File XML 
         set xmlData3 = xmlDoc3.getElementsByTagName("menu/item/titolo/testo") 
         For i3 = 0 To (xmlData3.length - 1) 
              Response.Write "[*]" & xmlData3.Item(i3).xml 
         Next 
         set xmlData3 = nothing 
         'Fine visualizzazione 
    Else 
         Response.Write "Impossibile caricare il File XMl... " & Server.HTMLEncode(xmlContent3) 
    End If 
    
    'Salviamo il File XML 
    xmlDoc3.save Server.Mappath("/public/nomeproductions.xml") 
    
    'Pulizia degli oggetti 
    Set xmlDoc3 = Nothing
    
    MySQL="Select charts from " & strTable
    	Set MyRs=MyConn.Execute(MySQL)
    	 
    	
    	dim charts
    	charts = MyRs("charts")
    
    'Inizializzo le Variabili 
    Dim xmlDoc4, root4 
    Dim xmlContent4, success4 
    Dim xmlData4 
    Dim i4 
    
    'Creo l' oggetto MsXML2.DOMDocument 
    Set xmlDoc4 = Server.CreateObject("msxml2.DOMDocument") 
    
    'Creo il Documento XML 
    xmlContent4 = "<menu>"
    xmlContent4 = xmlContent4 & "<item>" 
    xmlContent4 = xmlContent4 & "<titolo></titolo>" 
    xmlContent4 = xmlContent4 & "<testo>" & charts & "</testo>"  
    xmlContent4 = xmlContent4 & "</item>"
    xmlContent4 = xmlContent4 & "</menu>" 
    'Fine Creazione XML 
    
    'Controllo se il File XML sia stato caricato Correttamente 
    success4 = xmlDoc4.loadXML(xmlContent4) 
    If success4 = True Then 
         'Visualizzo tutti i dati nel File XML 
         set xmlData4 = xmlDoc4.getElementsByTagName("menu/item/titolo/testo") 
         For i4 = 0 To (xmlData4.length - 1) 
              Response.Write "[*]" & xmlData4.Item(i4).xml 
         Next 
         set xmlData4 = nothing 
         'Fine visualizzazione 
    Else 
         Response.Write "Impossibile caricare il File XMl... " & Server.HTMLEncode(xmlContent) 
    End If 
    
    'Salviamo il File XML 
    xmlDoc4.save Server.Mappath("/public/nomecharts.xml") 
    
    'Pulizia degli oggetti 
    Set xmlDoc4 = Nothing
        
    	Response.Redirect strFile
        MyConn.Close
    	set MyConn=nothing
    
    End Sub
    
    %>
    il problema è assurdo...nel senso che il codice funziona alla perfezione finchè non COPIO/INCOLLO NEL CAMPO DA MODIFICARE... se io scrivo normalmente il file xml mi viene creato con il contenuto corretto....se io copio/incollo da un altro testo nel campo...quando vado a modificare il server mi scrive un xml di LUNGHEZZA 0!!! come faccio ad ovviare a questo...è impossibile che io non possa fare un semplice copia/incolla nel campo da modificare...come devo fare???

  2. #12
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    ho capito tutto... c'entra si il copia/incolla ma è dovuto al benedetto carattere & che manda in errore il parser XML....quindi devo usare il CDATA...ora faccio subito una prova...ma che due p......

  3. #13

  4. #14
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    105
    Originariamente inviato da 7stars
    ho capito tutto... c'entra si il copia/incolla ma è dovuto al benedetto carattere & che manda in errore il parser XML....quindi devo usare il CDATA...ora faccio subito una prova...ma che due p......
    ecco...però che poi sorgono problemi su problemi...usando il CDATA poi mi scrive l'html come codice...quindi come si dovrebbe modificare ulteriormente??

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.