Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML parser save method

Status
Not open for further replies.

dandan86

Programmer
Jul 22, 2006
14
IL
Hey all,
I am sort of new in XML, here is my problem:
I am trying to update an XML document, for that matter I load it with a javascript code, and did some editting - only when try xmlDoc.save("filename.xml"); i get an error saying "permission denied" - So i can not save the xml and hence i can not update it.
here is the code in case it helps:

function f()
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note.xml");
xmlDoc.selectSingleNode("//to").setAttribute("urgent", "Dan");
document.write(xmlDoc.selectSingleNode("//to").getAttribute("urgent"));
xmlDoc.save("somefile.xml")
}

thanks in advance,

Dan
 
In what environment the script and the page are operating?
 
Thanks for replying,
In windowsXP PRO, on IE - i hope this is answers.

any clue?

 
The main differences come from whether the script is [1] from within a htm/asp/... [1.a] page server by a webserver or [1.b] in case of htm, serverd by the local file system; and [2] to save it to the local file system or [3] to save it back to the server in case of [1.b].

Maybe I would guess it is the simplest configuration you're on as you mention no webserver. In that case you can try this,
[tt] xmlDoc.save("file://d:/test/somefile.xml")[/tt]
or some folder in place of d:\test.

 
Thanks for replying.
Yes, for now I will settle for saving it on my hard-drive -so say i have the path: C:\Documents and Settings\DanC\Desktop\XML DOM

and i want the new XML file to be saved there? what should i write as an arguement to the save method?
i tried to somehow modify what you wrote but i got the same exception thing - "Permission denied"

thanks in advance,

Dan
 
Permission denied" is self explanatory. Are you allowed to save (write and change) to the folder or the file overwritten?
 
I am not trying to overwrite the file but create new one, I can easily create new files in that folder (right click---->new---->txt file) so i guess that means i can write in that folder - maybe there is something to change in teh folder settings?

thanks in advance,

Dan
 
oh, and - I know i can read from the file since I use document.write(xmlDoc.getSingleElement("//to").getAttribute("urgent");
and i do get the value of the attribute "urgent" printed (where "urgent" is an attribute of an element named "to" - obviously the deatils of the XML don't matter, just wanted to clerify that i can read from the file).

Thanks
 
Backslash (\) should be double-up (\\) in the path if you use it in the path.
 
and spaces (such as in: documents and settings) present no problem?

thanks
 
sry for double-posting:
i have tried to following:
xmlDoc.save("file://C:\\Documents and Settings\\DanC\\Desktop\\XML DOM\\somefile.xml");

and still get the same "Premission Denied" thing - any ideas?

thanks in advance,

Dan
 
Return again to the original question I asked. Maybe this time you need to be more precise: Is it a jscript with window script host hosting or jscript embedded inside a html page with internet explorer hosting but on a local file system?
 
this is the case:
The XML file and the ASP file will be on the same server, the ASP file will hold a JavaScript code which will perform the manipulation.

anyhow - for now i am just trying to test it on my own computer, using IIS and a simple ASP file with a javascript code - where the xml file is in the same folder as the asp file.
here is the code for the ASP file:

<html>
<script type="text/javascript">

function f()
{


var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note.xml");
xmlDoc.selectSingleNode("//to").setAttribute("urgent", "Dan");
document.write(xmlDoc.selectSingleNode("//to").getAttribute("urgent"));
var filename = "somexml.xml"
xmlDoc.save(filename)
}

</script>

<head>
<body>

<h1>Sales Dynamic Update Page</h1>
<br>

<form>
Sale Number:
<input type="text" name="SaleNumber" >
<br>
</br>
Sale Name:
<input type="text" name="SaleName" >
<br>
</br>
Sale Price:
<input type="text" name="SalePrice" >
<br>
</br>
Duration Dates:
<input type="text" name="SaleDuration" >
<br>
</br>
Sale Description:
<input type="text" name=SaleDescription" size="100">
<br>
</br>
<input type="button" name="updateButton" value="Update Values" onclick="f()">

</form>
</body>
</head>
</html>
 
Hey, someone tipped me that maybe it has to do with folder security options - that perhaps I have no atuhorizatino for creating files in the folder this way or something like that. can anyone shed a light over this? how do i change the folder security options?
 
[1]
>Hey, someone tipped me that maybe it has to do with folder security options - that perhaps I have no atuhorizatino for creating files in the folder this way or something like that.
Why don't you ask that someone? I asked you on the permission, and you emphatically said you can do anything on the folder.

[2] You have a very funny idea of html page structure. Why do you put the body inside a head section?

[3]
>anyhow - for now i am just trying to test it on my own computer, using IIS and a simple ASP file with a javascript code - where the xml file is in the same folder as the asp file.
But you never answer clearly---may be you have no idea---is the "asp" (actually a html page) is served via the iis localhost? or by double click on the html page with extension .htm or .html. (You don't have to feel bad testing on the local computer, that's how everybody develops pages. Those who pretend otherwise often do not nothing except copying.)
 
when i open the ASP file (i know that for now it looks like an html one, and i know i am rather clueless), I go to Internet Explorer and on the address bar type the following:

so i guess that means i use the iis localhost?

thanks for your willingness to help.

Dan
 
Alright, I think it is indeed the folder option thing, Instead of writing in javascript i wrote it in ASP, here is the code:
<html>
<body>
<%
dim xmlDom, Onode
set xmlDom = Server.CreateObject("MSXML2.DOMDocument.4.0")
xmlDom.load("Server.Mappath("note.xml"))

//checking for parser load error - no need to write that
//some edditing on the xml:
set oNode = xmlDom.DocumentElement.SelectSingleNode("to")
oNode.setAttribute "urgent", "maybe"
if not oNode is nothing then
Response.Write(Server.HTMLEnconde(oNode.getAttribute("urgent")))
end if

*this printout works - the attribute "urgent" is changed"

xmlDom.save(Server.Mappath("somefile.xml"))
%>
</body>
</html>

now, i run the whole thing just as i stated above, using IIS localhost on my own laptop.
the last line, i.e the use of the save method, result to the following error in Internet Explorer:

Error Type:
msxml3.dll(0X80070005)
Access is denied
/myWeb/test1.asp, line 21

i have the feeling it has to do with the folder/server definitions.

anyone knows how to change those?

thanks again,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top