• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2288
  • Last Modified:

Permission Denied problem - xmlDoc.save("note.xml")

Hi Pals
     I have xml file. I want to append new elemnt and save the same using VBScript/JavaScrip with HTML alone(Not ASP or VB).But while saving the file Permission Denied error has occured.Here I have paste the code.

Code:

<script type="text/vbscript">
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")

document.write("The original XML:")
document.write("<xmp>" & xmlDoc.xml & "</xmp>")

set newnode=xmlDoc.createElement("cancel")
set newtext=xmlDoc.createTextNode("I must cancel")
newnode.appendChild(newtext)
xmlDoc.documentElement.appendChild(newnode)

document.write("After appending the new node:")
document.write("<xmp>" & xmlDoc.xml & "</xmp>")
xmlDoc.save ("note.xml")  --- Error line
}
</script>

End of Code


Expecting reply.

Happy programming......
Prabhu


0
prabhujrp
Asked:
prabhujrp
  • 2
1 Solution
 
mikkolsoftCommented:
That sounds a little bit too dangerous if you could write a HTML file that when loaded up, could save a file into Client's machine right? So I don't think the browser could let you do such a thing.

Mikkol
0
 
sparkplugCommented:
Is only possible to save data to the client machine using cookies or the userData behaviour. http://msdn.microsoft.com/workshop/author/behaviors/reference/behaviors/userdata.asp

Here is an example of how to save XML on the client using the userData behaviour:

<html>
<meta name="save" content="userdata">

<style type="text/css">
  .userData { behavior:url(#default#userdata); }
</style>

<script type="text/vbscript">

     Set xmlDoc=CreateObject("Microsoft.XMLDOM")
     xmlDoc.async="false"

     Sub init()
          Call xmlDoc.loadXML("<xmp></xmp>")

          txtNotes.value=xmlDoc.xml

     End Sub

     Sub loadNotes()
          Call spNotes.load("notesInfo")
          sSavedXML = spNotes.getAttribute("notesXML")
          If sSavedXML <> "" Then
               Call xmlDoc.loadXML(sSavedXML)
               txtNotes.value=xmlDoc.xml
          End If
     End Sub

     Sub saveNotes()
          sXML = xmlDoc.xml
          If Not xmlDoc.loadXML(txtNotes.value) Then
               MsgBox("Error parsing XML: " & xmlDoc.parseError.reason)
               xmlDoc.loadXML(sXML)

          Else
               Call spNotes.setAttribute("notesXML", xmlDoc.xml)
               Call spNotes.save("notesInfo")
          End If
     End Sub

     Sub addNote()

          Set oNewNode=xmlDoc.createElement("note")
          oNewNode.text=newNote.value
          Call xmlDoc.documentElement.appendChild(oNewNode)
          txtNotes.value=xmlDoc.xml
     End Sub
</script>
<body onload="init()">
<input type="button" value="load" onclick="loadNotes"/>
<input type="button" value="save" onclick="saveNotes"/>
<br/>
<input type="text" value="type note to add here" id="newNote"/>
<input type="button" value="add" onclick="addNote" /><br/>
<span class="userData" id="spNotes"/>
<textarea cols="80" rows="20" id="txtNotes">test</textarea>
</body>
</html>

Hope this helps,

S'Plug<

0
 
sparkplugCommented:
Note the XML is saved in one of the subdirectories of the folder:
C:\Documents and Settings\your username\UserData\

where 'your username' is the username you use to login.
It will be named notesInfo[1].xml

>S'Plug<
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now