开发者

create and modify xml file using javascript (want to save xml file on client side)

How to save xml file on client side using javascript...?

        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else // Internet Explorer 5/6
        {
        开发者_如何学C    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", "User.xml", false);
        xhttp.send("");
        xmlDoc = xhttp.responseXML;

        xmlDoc.getElementsByTagName("Username")[0].childNodes[0].nodeValue = 'asdasf';
        xmlDoc.getElementsByTagName("password")[0].childNodes[0].nodeValue = 'asdAS';
        xmlDoc.getElementsByTagName("UserId")[0].childNodes[0].nodeValue = '12';
        xmlDoc.save("User.xml");

this is not working.. showing error as save is not a function.

Thanks Suneetha.


This is not allowed in JavaScript. This will be a security vulnerability.

Read JavaScript security

JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files. Second, scripts are constrained by the same origin policy: scripts from one web site do not have access to information such as usernames, passwords, or cookies sent to another site. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox.


You can't save a file on the client side, you won't have the access rights


you should save a file using a server side language to save locally to your server, you are not allowed to save on the client side.


If your target browser has localStorage, you can use that to save data on the client side.

Check quirksmode for compatibility, which at this point in time is pretty limited.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜