Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Trouble saving xmlDom object Trouble saving xmlDom objectTo: NULL Date: 11/2/2005 10:26:00 AM Hi,
I am trying to make a simple ASP script that creates a xmlDom object,
opens a file "authors-test.xml", creates a new <author> entry, adds it
to the xmlDom object, and then saves the xmlDom object.
I appear to be having trouble saving the xmlDom object. I get "Access
Denied" error when I use the xmlDom.save method. I have enabled read
and write permissions for the directory containing "authors-test.xml".
Does anybody have any idea what may be the problem? Or is there
another, better, way to save a modified xmlDOM object back to the file
it has been loaded from.
I'm including my code below, it is from a file called "addAuthor.asp"
that is called by a form in another html file.
-----------
<%
'---------------------------------------------------------------------------
'This file contains a Function addAuthor that takes two paramaters:
'strXMLFileName - The string name of the XML file containing the
authors.
'strPath - The string path indicating the location of the authors XML
file.
'===========================================================================
Function addAuthor(strXMLFileName, strPath)
Response.write("In Function")
' Declare local variables.
Dim xmlDom
Dim xmlPI
Dim newAuthor
Dim authorID
Dim firstName
Dim middleName
Dim lastName
Dim elementText
' Create XML DOM object.
set xmlDom = Server.CreateObject("Microsoft.XMLDOM")
xmlDom.async = "false"
xmlDom.load(strPath & "\" & strXMLFileName)
Response.write("here")
' Create new author node.
set newAuthor = xmlDom.createElement("author")
set authorID = xmlDom.createElement("authorID")
set elementText = xmlDom.createTextNode(Request.Form("authorID"))
authorID.appendChild(elementText)
set firstName = xmlDom.createElement("first_name")
set elementText = xmlDom.createTextNode(Request.Form("firstName"))
firstName.appendChild(elementText)
set middleName = xmlDom.createElement("middle_name")
set elementText = xmlDom.createTextNode(Request.Form("middleName"))
middleName.appendChild(elementText)
set lastName = xmlDom.createElement("last_name")
set elementText = xmlDom.createTextNode(Request.Form("lastName"))
lastName.appendChild(elementText)
newAuthor.appendChild(authorID)
newAuthor.appendChild(firstName)
newAuthor.appendChild(middleName)
newAuthor.appendChild(lastName)
Response.write ("About to insert.")
xmlDom.insertBefore newAuthor, xmlDom.childNodes(0)
Response.write ("About to save.")
xmlDom.save strPath & "\" & strXMLFileName
' Release all references.
xmlDom = Nothing
xmlPI = Nothing
newAuthor = Nothing
authorID = Nothing
firstName = Nothing
middleName = Nothing
lastName = Nothing
textElement = Nothing
End Function
' On error write error description and exit.
On Error Resume Next
' Call addAuthor function.
addAuthor "authors-test.xml","\XMLNotesProject"
'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.")
'End If
Response.write(Err.Description)
If Err.number <> 0 then
Reponse.write "Error Occured: " & Err.Description
Else
Reponse.write("Submission worked.")
End If
%>
Best,
ezmiller
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
