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.
-
You would need to use PHP, Java, or some other "backend" language to save it and a server to save it to, but yeah, totally possible.KJ Price– KJ Price2014-07-31 15:13:58 +00:00Commented Jul 31, 2014 at 15:13
-
Is it possible to generate XML inside HTML? Without creating XML file before it on server.snuuve– snuuve2014-07-31 15:16:49 +00:00Commented Jul 31, 2014 at 15:16
-
HTML is XML formatted already. Not sure exactly what you mean by that. Take for example what happens in the Stack Overflow answer box. The user has the ability to type in html. The html will be saved along with the rest of the user's comment and then rendered on the page as HTML. I don't see a reason to turn it into actual XML. Check this out to see the difference between XML and HTML.KJ Price– KJ Price2014-07-31 15:20:53 +00:00Commented Jul 31, 2014 at 15:20
-
I will explain what i want to do. I have program wrote in HTML/jQuery/CSS. Main task of this programme is generate table by jQuery. In this table i can click on cells and change their background. Then i want to save it. For now i save it as image ( html2canvas) but i need also save it with data ( binary, the best option is XML). So question is, is it possible to generate XML object by jQuery-java inside my HTML programme. Then i would style it for looking same as my HTML <table> is looking now. Then i want save it as XML. Only this "table".snuuve– snuuve2014-07-31 15:27:20 +00:00Commented Jul 31, 2014 at 15:27
Add a comment
|
1 Answer
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:
7 Comments
snuuve
Thanks, i will check it. But i will have server for it,so saving isnt main problem here.
Moonsurfer_1
Yeah, I noticed after responding, so I edited my answer to provide more instructions for generating xml. ;)
snuuve
Thanks, its helpfull. But i have more questions now ;p Here is fiddle of table generator : jsfiddle.net/7g9rc . How to add something in xml elements for example: add "red" into COLOR. From other side, how to generate this "xml table" instead of "html table". I would like to make only xml table coz then if i will click on cells its gonna be hard to change data in "xml table" from "html table" events. I hope you understand my thinking ;p
Moonsurfer_1
Do I understand correctly that you just want to add the text "red" inside the COLOR xml element? Like this? <COLOR>red</COLOR>. I added the explanation for doing this to my answer as formatting in comments doesn't seem to work correctly.
snuuve
I think i gonna do it other way. Add data to each <td> ( data-* from HTML5) and then get this values and generate XML file from it. I think its gonna be easier. Question now is how to generate XML with these datas to file.xml ;p Anyway, thank you, you help me alot.
|