2

I am developing an application which requires the reading and writing of XML files. Reading I've got covered, but is writing possible at all? The layout of my webapp is like this:
../includes/ (irrelevant)
../content.xml (xml to be written to)
../index.html (irrelevant)
../admin.html (file to write with)
Any help appreciated, thanks.

Jason
  • 33
  • 3

2 Answers2

5

You will need to write some type of form handler or web service on the server side. Once this is done you can use AJAX to call the form handler or service and submit data that way.

Example- form.html -> submit -> formhandler.php -> content.xml

HurnsMobile
  • 4,341
  • 3
  • 27
  • 39
  • Thanks for the response buddy. Is it possible to do this without PHP or any other server-side language? Just HTML and JS? I've seen things like TiddlyWiki which allow editing of pages remotely. – Jason Aug 16 '10 at 13:19
  • No, this will require some amount of work on the server-side. TiddlyWiki for example is written in java (iirc) – HurnsMobile Aug 16 '10 at 13:21
  • So would it be possible then to have just a single PHP file with the sole task of writing XML files, while everything else could be HTML (i.e parsing and reading XML)? – Jason Aug 16 '10 at 13:26
  • Yes. Simply write a php file that takes data with `$_POST` and writes it to your backend XML. Then use jQuery `$.post` to submit whatever data you would like to it. – HurnsMobile Aug 16 '10 at 13:34
  • A good/concise example of this - http://www.talkphp.com/vbarticles.php?do=article&articleid=58&title=simple-ajax-with-jquery – HurnsMobile Aug 16 '10 at 13:41
  • Righty. So there is absolutely no way, difficult or not and without using server-side scripts, to write to a remote file? If so, I'll have to resort to the single PHP file solution. Many thanks HurnsMobile. – Jason Aug 16 '10 at 13:45
1

Unless you are hacking a web server, you cannot write to a server from a client-side script written in javascript, java, actionscript, etc.

This is because basic web server security does not allow a script from a foreign source (your pc, for example) to write to files on the server. If it did, anyone with any small knowledge of web programming would be able to change the content of websites at will and without limitation.