Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Help!

    Questi sono i file... manca il file XML, ed infondo i sono le mie prime domande... ne farò molte altre se è leito e non vi rompo

    FORM HTM

    codice:
    <html>
    <head>
    <title>Appending data into XML Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name='author' contents='Trina Thach'/>
    </head>
    <body>
    <form name='thisform' method='post' action='appending.asp'>
    <table border='1'>
    <tr>
    <td>Employee Name</td>
    <td><input type='text' name='empname' size='30'/></td>
    </tr>
    <tr>
    <td>Employee Age</td>
    <td><input type='text' name='empage' size='30'/></td>
    </tr>
    <tr>
    <td><input type='reset' name='reset' value='Reset'></td>
    <td><input type='submit' name='submit' value='Append Now'></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    PROCESSORE ASP:

    codice:
    <html>
    <head>
    <title>Appending data into XML Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name='author' contents='Trina Thach'/>
    </head>
    <body>
    <%
    dim objXMLDoc, objCurrNode, objNewNode, objNewText, ename, eage
    
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM") 
    objXMLDoc.async = False 
    
    ' Open the employees.xml database
    objXMLDoc.load Server.Mappath("employees.xml") 
    
    if objXMLDoc.ParseError <> 0 then
    	Response.Write ("Error: Could not get the source")
    else
    	' Say example, ename entered was "Peter Chang"
    	ename = Request("empname")
    	eage= Request("empage")
    	
    	' Create empty element <name></name>
    	Set objNewNode = objXMLDoc.createElement("name") 
    	
    	' Create a text node, value is the employee name "Peter Chang"
    	' that operator enter from the form previously
    	Set objNewText = objXMLDoc.createTextNode(ename) 
    	
    	' Append empname value into element <name>. 
    	' The result is <name>Peter Chang</name>
    	objNewNode.appendChild(objNewText) 
    
    	Set objCurrNode = objXMLDoc.documentElement
    	
    	' Now, append the new node <name>Peter Chang</name> 
    	' into employees.xml database
    	objCurrNode.appendChild(objNewNode)
    	
    	' Create empty element <name></name>
    	Set objNewNode = objXMLDoc.createElement("age") 
    	
    	' Create a text node, value is the employee name "Peter Chang"
    	' that operator enter from the form previously
    	Set objNewText = objXMLDoc.createTextNode(eage) 
    	
    	' Append empname value into element <name>. 
    	' The result is <name>Peter Chang</name>
    	objNewNode.appendChild(objNewText) 
    
    	Set objCurrNode = objXMLDoc.documentElement
    	
    	' Now, append the new node <name>Peter Chang</name> 
    	' into employees.xml database
    	objCurrNode.appendChild(objNewNode)
    
    	' Save the employees.xml database
    	objXMLDoc.save Server.Mappath("employees.xml")
    
    	' Once the file has been saved, we are DONE. But for safety reason, 
    	' we'd better double check by printing out the last node.
    
    	' Set cursor to the last element in employees.xml
    	' which is the one you just added ie. Peter Chang
    	Set objCurrNode = objXMLDoc.documentElement.lastChild
    	
    	' Print out the name and brief message to check whether
    	' the name has added into database sucessffully
    	Response.Write("Employee ")
    	Response.Write(objCurrNode.xml)
    	Response.Write(" has been added sucessfully into the database.")
    	
    End if
    ' Free up memory
    set objXMLDoc = nothing
    
    %>
    </body>
    </html>

    QUESITI:

    1. Come posso aggiungere l'elemento "age" all'elemento "name" anzichè farlo all'elemento "note" (root) ????

    qui: Set objCurrNode = objXMLDoc.documentElement

    2. Dato che le operazioni di "appending" di name e age sono praticamente identiche... c'è un modo per evitare di scrivere il codice ogni santa volta?

    3. Se voglio salvare il file in una locazione diversa come lo scrivo?

    PS: Scusate ma sono i miei primi esperimenti on DOM e XML . il codice non l'ho generato tutto da solo, ma sto imparando a modificarlo per acquisirne le nozioni. Sono un grafico web&press e non ho mai programmato
    Per esigezenze di lavoro sto studiando il mondo XML... faccio bene?

  2. #2
    Certo che fai bene, però penso che se non hai mai programmato sarebbe bene partire da qualcosa di più semplice...

    Comunque:

    1) objXMLDoc.documentElement.childNodes.item(idnodo). appendChild(objNewNode)

    2)no, però lo puoi semplificare:
    Set objNewNode = objXMLDoc.createElement("nome")
    objNewNode.Text = "quello che vuoi"
    objXMLDoc.documentElement.appendChild(objNewNode)
    Set objNewNode = nothing

    3)objXMLDoc.save Server.Mappath("/tualocazione/employees.xml")

    un'ultima cosa, facendo solo:

    set objXMLDoc = nothing

    non pulisci tutta la memoria. dovresti anche fare ad esempio:

    Set objNewNode = nothing
    Set objNewText = nothing

    eccetera

    ciao
    www.minifloppy.it - Dove ASP, XML, XSLT si incontrano...

    Io arrivo sempre tardi in ufficio, ma cerco di rimediare andando via presto

  3. #3
    Non funge...mi da un errore.... vedi in fondo alla pagina

    codice:
    APPENFORM.HTM
    
    <html>
    <head>
    <title>Appending data into XML Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name='author' contents='Trina Thach'/>
    <link href="ti.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <form name='thisform' method='post' action='appending.asp'>
     <table border='0' class="border_b">
      <tr> 
       <td width="121" class="normale">MODELLO</td>
       <td width="150"><input name='empmodello' type='text' class="normale" id="empmodello" size='30'/></td>
      </tr>
      <tr> 
       <td class="normale">ANNO</td>
       <td><input name='empanno' type='text' class="normale" id="empanno" size='30'/></td>
      </tr>
      <tr> 
       <td class="normale">DETTAGLI</td>
       <td><input name='empdettagli' type='text' class="normale" id="empdettagli" size='30'/></td>
      </tr>
      <tr> 
       <td class="normale">DISPONIBILITA</td>
       <td><input name='empdisp' type='text' class="normale" id="empdisp" size='30'/></td>
      </tr>
      <tr> 
       <td class="normale">KILOMETRI</td>
       <td><input name='empkm' type='text' class="normale" id="empkm" size='30'/></td>
      </tr>
      <tr> 
       <td><div align="center"> 
         <input name='reset' type='reset' class="normale" value='Resetta'>
        </div></td>
       <td><div align="center"> 
         <input name='submit' type='submit' class="normale" value='Aggiungi'>
        </div></td>
      </tr>
     </table>
    </form>
    </body>
    </html>
    codice:
    LA PAGINA ASP
    
    <title>Appending data into XML Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    
    <%
    
    dim objXMLDoc, objCurrNode, objNewNode, objNewText,emodello, eanno, edettagli, edisp, ekm
    
    
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM") 
    objXMLDoc.async = False 
    objXMLDoc.load Server.Mappath("prodotti.xml") 
    
    if objXMLDoc.ParseError <> 0 then
    	Response.Write ("Error: Could not get the source")
    
    
    else
    
    	Set objNewNode = objXMLDoc.createElement("prodotto") 
    	objXMLDoc.documentElement.appendChild(objNewNode)	
    
    
    	emodello = Request("empmodello")
    	Set objNewChild = objXMLDoc.createElement("modello") 
    	objNewChild.Text = emodello
    	objNewNode.appendChild(objNewChild)
    	Set objNewChild = nothing	
    
    
    	eanno = Request("empanno")
    	Set objNewChild = objXMLDoc.createElement("anno") 
    	objNewChild.Text = eanno
    	objnewNode.appendChild(objNewChild)
    	Set objNewChild = nothing
    
    	edettagli = Request("empdettagli")
    	Set objNewChild = objXMLDoc.createElement("dettagli") 
    	objNewChild.Text = edettagli
    	ObjnewNode.appendChild(objNewChild)
    	Set objNewChild = nothing
    
    	edisp = Request("empdisp")
    	Set objNewChild = objXMLDoc.createElement("disponibilita") 
    	objNewChild.Text = edisp
    	ObjnewNode.appendChild(objNewChild)
    	Set objNewChild = nothing
    	
    	ekm = Request("empkm")
    	Set objNewChild = objXMLDoc.createElement("km") 
    	objNewChild.Text = ekm
    	ObjnewNode.appendChild(objNewChild)
    	Set objNewChild = nothing
    
    	
    
    	objXMLDoc.save Server.Mappath("prodotti.xml")
    
    	
    	Response.Write("I dati sono stati aggiunti con successo!")
    	
    End if
    ' Free up memory
    set objXMLDoc = nothing
    
    %>
    </body>
    </html>
    codice:
    PRODOTTI.XML
    
    <?xml version="1.0"?>
    <catalogo>
    </catalogo>
    codice:
    Impossibile visualizzare la pagina 
    Si è verificato un problema a livello della pagina che si desidera visualizzare che ne impedisce la visualizzazione. 
    
    --------------------------------------------------------------------------------
    
    Please try the following:
    
    Fare clic sul pulsante Aggiorna o riprovare più tardi.
    
    Aprire la localhost home page e cercare i collegamenti alle informazioni desiderate. 
    HTTP 500.100 - Errore interno del server - errore ASP
    Internet Information Services
    
    --------------------------------------------------------------------------------
    
    Informazioni tecniche (per il personale del supporto tecnico)
    
    Tipo di errore:
    msxml3.dll (0x80070005)
    Accesso negato. 
    /myweb/camion/appending.asp, line 60
    
    
    Tipo di browser:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) 
    
    Pagina:
    POST 70 bytes to /myweb/camion/appending.asp
    
    POST Data:
    empmodello=f&empanno=f&empdettagli=f&empdisp=f&empkm=f&submit=Aggiungi 
    
    Ora:
    sabato 15 marzo 2003, 12.04.14 
    
    
    Informazioni aggiuntive:
    Supporto Microsoft

  4. #4
    Porcaccia la miseria... il codice era scritto bene e solo che non mi funzionava sul IIS... l'ho spostato in un altra cartella sempre all'interno di wwwroot e funziona!

    Com'è sto fatto? Un bug che non conosco?

  5. #5
    Utente di HTML.it L'avatar di Toeke
    Registrato dal
    Aug 2002
    Messaggi
    348
    @boubo
    Ho modificato il titolo della discussione poiche' prima era troppo generico.
    In base al Regolamento la prossima volta chiudo




    Toeke

  6. #6
    Utente di HTML.it
    Registrato dal
    Jun 2001
    Messaggi
    1
    Forse non hai dato i diritti in scrittura al file .xml

    Mauro

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 © 2024 vBulletin Solutions, Inc. All rights reserved.