0

I need to edit an xml file using javascript. Now I'm involved in a project of online testing.

The question.xml file is already in the project folder.

In that i want to add or edit the questions(only using javascript). I'm able to bring the particular content through ajax, but I am not able to edit the file.

1
  • Where does the file come from? Is it uploaded by a user through your web application? Or does it reside on the server? Update your question with the answer. Commented Dec 4, 2008 at 6:17

6 Answers 6

5

Javascript can't write to a file. The best you'll be able to do is get Javascript to read and edit the XML then post that data to a server-side script to write to file.

Sign up to request clarification or add additional context in comments.

1 Comment

This was historically true, but browsers are now able to modify local files using the File System Access API.
1

Until now, Google Chrome is the only web browser that has a functioning implementation of the FileSystem API, therefore, it may allow you to save files locally using only Javascript.

Obviously, for security reasons, when writing files to the local file system, the user must explicitly allow it.

A working tutorial: http://www.html5rocks.com/en/tutorials/file/filesystem/

Comments

0

Nickf is correct. The reason Javascript can't write to a file is because it is a Client-Side language. Javascript will never have permission to write a file because it has to operate inside the browser sandbox.

You will need to use a server-side script (.NET, PHP, ColdFusion, etc) to write the file.

Comments

0

If you are willing to use Google Gears, you get a sandbox on the client machine on which you can write files.

1 Comment

Google Gears was cancelled in 2011 (3 years after this post). This answer is historically accurate but no longer relevant (with the intro of HTML 5). Although, at the moment, Chrome is the only browser which actually implements the file system api.
0

Javascript has no built-in file I/O (a.k.a. you can't do it with JS alone)

Instead use some kind of server side language such as PHP or ASP.NET in conjunction with Javascript's AJAX functionality.

1 Comment

nitpicking a little bit here, but you're not right about the File IO thing. it does have file INput, just not OUTput.
0

Look over Adobe's Flex development system. There are ways you can use it to build an app that runs in the browser (or not) and can access the filesystem (Windows/Mac/Linux). It's programmed in ActionScript, a dialect of javascript; and can interoperate with javascript in the browser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.