?
Solved

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

Posted on 2003-03-13
5
Medium Priority
?
2,226 Views
Last Modified: 2007-12-19
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
Comment
Question by:prabhujrp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 2

Expert Comment

by:mikkolsoft
ID: 8137456
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
 
LVL 9

Accepted Solution

by:
sparkplug earned 80 total points
ID: 8146224
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
 
LVL 9

Expert Comment

by:sparkplug
ID: 8146231
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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question