PDA

View Full Version : how do I update xml nodes with a .asp?


dudeamisgriff
08-30-2008, 02:30 PM
this is driving me crazy. I'm looking to update an xml node with .asp based on user input. say this is my xml file



<people>

<userID>1
<fname>Walt</fname>
<lname>Grover</lname>
</userID>

<userID>2
<fname>Steve</fname>
<lname>Davids</lname>
</userID>

</people>



and the html includes a form with two text boxes that post to the asp that updates the xml.

harbingerOTV
11-11-2008, 05:32 AM
maybe this can help out.


<%

text="<gallery>"
text=text & "<entry>"
text=text & "<caption>" & Request.Form("caption") & "</caption>"
text=text & "<image>" & Request.Form("image") & "</image>"
text=text & "</entry>"
text=text & "<entry>"
text=text & "<caption>" & Request.Form("caption1") & "</caption>"
text=text & "<image>" & Request.Form("image1") & "</image>"
text=text & "</entry>"
text=text & "</gallery>"

set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(text)

xmlDoc.Save("gallery.xml")

'Test to see if an error occurred, if so, let the user know.
'Otherwise, tell the user that the operation was successful.
If err.number <> 0 then
Response.write("Errors occurred while saving your form submission.")
Else
Response.write("Your form submission has been saved.<br><a href='default.asp'>Return to admin panel</a><br>")
Response.write("<a href='gallery.xml'>View XML</a>")
End If
%>


giving that your form called this page it would output a flat XML file called gallery.xml formatted like:


<gallery>
<entry>
<caption>This is my first picture</caption>
<image>pic1.jpg</image>
</entry>
<entry>
<caption>This is my second picture</caption>
<image>pic2.jpg</image>
</entry>
</gallery>


it WILL overwrite any existing gallery.xml file in the same folder.


doh! didnt realize how old this thread was but, I am currently doing the same thing so...