Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Trouble saving xmlDom object

From: "ezmiller" <ethanzanemiller@-----.--->
To: 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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent