0

So I have a xml document loaded in JavaScript variable.

Xml looks like this:

<root>  
    <pp>test<ii>sample italic</ii> text after italic</pp>  
</root>

Then I have an input box where the content of <pp> element is written out.

Like this: test<ii>sample italic</ii> text after italic

Note that text in input box contains Xml tags.

User can then change the text in input box. Like so: test<ii>sample BB italic</ii> and <bb>bold </bb> text after

Now I need to save this modified text back to Xml variable.

How do I do that?

EDIT 1
Question has nothing to do with saving to actual file. I just need to save/change modified data back to Xml variable.

2 Answers 2

1

Maybe you could look at this link it would probably help you : http://www.ehow.com/how_5933380_change-values-xml-javascript.html

Or here, those are two goo tutorial : http://www.devguru.com/features/tutorials/xml_javascript/xml_javascript.asp

Are you reading your xml from a file ?

To create a node :

var theNewParagraph = document.createElement('p'); var theTextOfTheParagraph = document.createTextNode('Some content.'); theNewParagraph.appendChild(theTextOfTheParagraph); document.getElementById('someElementId').appendChild(theNewParagraph);

Taken from this : http://www.howtocreate.co.uk/tutorials/javascript/dombasics

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

4 Comments

That loads the XML file and enables you to edit the nodes, but there is no mechanism to save the file.
Okay, so the XML file is locally? I did not know that.
Changing value directly on nodes that exist isn't a problem. How do I add that <bb></bb> to nodes list?
0

You will need to send the data via Ajax to a server-side script, that handles the rewriting of the file. Client-side Javascript cannot solve this problem.

3 Comments

But I need to modify the content of variable. Saving to file is not the problem here.
Why don´t you send a string containing your XML to the server script like that: "<root><pp>" + document.getElementById("yourInputBox").value + "</pp></root>"?
Becouse xml is a lot more complicated then this sample, and I need to keep it as DOMDocument all the time, not as string.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.