How to save XML file using JScript/DOM in IE
Greetings all,
I'm a new member to this group, I'm having a bit of a problem with the IXMLDocument's save method and I'm not sure how to fix it.
I have a javascript function SaveToXML in which I'll load existing xml file to msxml2.DOMDocument.4.0 object. Then I added new nodes to Root element of the XMLDoc and I'm trying to save it to the same xml file.
At the end of the script I used the line "alert(xmlDoc.xml)" to see that my XML has been revised (this is for debugging only) and then use the line "xmlDoc.save(filename)". I'm able to see my expected changes in alert but not in xml file on disk.
The problem here is XMLDoc.Save(filename) is not intended for use from a secure client, such as Microsoft® Internet Explorer. I can able to save to file from View mode in Visual Studio InterDev 6.0. Can anybody help me to save xml file using JScript and DOM without using Server objects. I put security level to low for IE 6.0 on my work station.
I am trying to do a simple GuestBook for my site using XML, almost finished this except for this problem and have wasted countless hours trying different things and scouring the web for help. If anyone out there can help me with this, I would greatly appreciate it.
Here is the function I'm using:
function WriteToXML()
{
var Node
var NodeN
var xmlDoc, xmlPersist
var root
x=document.myForm
xmlDoc= new ActiveXObject("msxml2.DOMDocument.4.0")
xmlDoc.validateOnParse = true
xmlDoc.async = false
xmlDoc.load("GuestBook.xml")
root = xmlDoc.documentElement
//alert(root.xml)
Node = xmlDoc.createNode(1, "Guest", "")
nodeP = xmlDoc.createAttribute("confidential")
nodeP.value="C"
Node.attributes.setNamedItem(nodeP)
root.appendChild(Node)
NodeN=xmlDoc.createNode(1, "Name", "")
NodeN.text=x.Name.value
Node.appendChild(NodeN)
NodeE=xmlDoc.createNode(1, "Email", "")
NodeE.text=x.Email.value
Node.appendChild(NodeE)
NodeW=xmlDoc.createNode(1, "Website", "")
NodeW.text=x.Website.value
Node.appendChild(NodeW)
NodeC=xmlDoc.createNode(1, "Comments", "")
NodeC.text=x.Comment.value
Node.appendChild(NodeC)
// working fine..
alert(root.xml)
xmlDoc.save("GuestBook2.xml") // can't use filename as IE won't allow
alert("Something getting wrong")
}
|