How to save xml files using javascript?

I tried

1) load the xml file using javascript as an object, say note.xml

2), then save the object in a new XML file, say note_new.xml

I did 1) but failed 2)

I tried using the save () method to execute 2). After my failure, I checked the ms site and they said save () is not supported ....

can someone enlighten me how to make conservation?

Thank you!

here is the code:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <h1>W3Schools Internal Note</h1> <p><b>To:</b> <span id="to"></span><br /> <b>From:</b> <span id="from"></span><br /> <b>Message:</b> <span id="message"></span> <script type="text/javascript"> if (window.ActiveXObject){ alert("there is ActiveXObject"); var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("note.xml"); }else{ alert("i am not withActiveXObject!"); xhttp=new XMLHttpRequest(); xhttp.open("GET","note.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; } xmlDoc.save("note_new.xml"); </script> </body> </html> 

update:

this seems to be related to a security issue. I am adapting to those experienced programmers who put this question in a hurry because it is a question for beginners.

+4
source share
1 answer

Your problem: javaScript does not have an input / output ( I/O ) API, since it is a client-side scripting language and therefore does not have access to the file system through the server. To save data on the server, you will need to use the server-side scripting language. There may be hacks to solve your problem on the client side, but they are probably either unsafe or may be erroneous. (btw: which api is a member of the save method? did you do this?)

What you can do is temporarily save data for any DOM object (like windows or javaScript). However, there is no way to make these changes permanent.

In your case, searching for PHP scripts may be the best way.

+6
source

Source: https://habr.com/ru/post/1309257/


All Articles