XML in HTML and then save XML as file?

snuuve

Is it possible to generate by javascript table which one is styled XML form, make some edits with data etc by users and then save this table as XML file? Im new with XML and have some problems with it, i know its stupid question.

Moonsurfer_1

You can take a look at this FileSaver library: https://github.com/eligrey/FileSaver.js

It should be able to do what you're after: saving without having to use a server backend.

As for XML generation: You can just use the createElement and appendChild functions for that.

    var xml = document.createElement("root");
    var node = document.createElement("rootchild");
    node.appendChild( document.createElement("something") );
    node.appendChild( document.createElement("somethingelse") );
    node.appendChild( document.createElement("somethingdifferent") );
    xml.appendChild(node);

    alert(xml.innerHTML);

As for your secondary question in the comments below:

If you want to add "red" to the color element you only need to do this:

    var colorNode =  document.createElement("COLOR");              
    var colorText = document.createTextNode("red");
    colorNode.appendChild(colorText);
    node.appendChild(colorNode );

If you need any more information, I suggest you take a look at the reference documentation of w3schools:

http://www.w3schools.com/jsref/dom_obj_all.asp

http://www.w3schools.com/jsref/dom_obj_document.asp

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related