views:

950

answers:

5

I have an XML DB and I have been able to parse the XML using DOM with JS. The thing I am unable to figure out is, how can I change a value in my XML db?

I tried using:

xmlDoc.getElementsByTagName("COMMENT")[0].childNodes[0].nodeValue="text";

But this does not changes the actual DB. When I refresh my page, it gives me the same old value again.

What am I doing wrong?


Edit:

I am making changes only on the client page and not sending the data back to make relevant changes in database itself.

I understand I should use AJAX or something, but could you please give me directions on what I should read or some examples where I can learn?

A: 

You've told us basically no relevant info, but most likely you're just changing the client page, and making no effort to send back (e.g. with a form or AJAX) the changes.

Matthew Flaschen
A: 

You need to save db after changes. It is not possible with DOM and JS on Web Browser, so you should use AJAX or sth similar to process XML

Tolgahan Albayrak
A: 

Edited out.

Please read the FAQ, and lurk on the site so you understand how it works.

Zeeshan Rang
This is not an answer. Leave a comment or edit your question.
Geoffrey Chetwood
+1  A: 

You cannot write to XML with JavaScript, only load a copy of the XML DOM into memory and manipulate that copy. Obviously that is destroyed when the JS instance restarts (reloading the page) or you re-load from the original file.

If the XML is on the server, you will need a server-side language such as PHP, ASP.NET, Ruby on Rails, etc. to write anything to disk on the server. That code executes on the server, not in the browser.

To communicate between your JavaScript code and your server-side code, AJAX is the answer. A List Apart has a good resource for getting started. The simplest model that comes to mind is using AJAX to send the complete, modified XML chunk to server-side code, which simply saves it.

If you are dealing with huge files and frequent updates, you may want to consider using AJAX to send manipulation instructions to the server-side code, which execute the changes and save the file.

Rex M
THanks Rex. I believe i have to read about AJAX first to do this. Zeeshan
Zeeshan Rang
A: 

Hey again,

I read some where that XmlDocument and XMLNode classes can be used to change the value of the node in XML data. Is this possible to do?

And if it is, where can i get a sample where it explains how to do it.

Thank you in advance.

Best Zeeshan

Zeeshan Rang