Jump to content

<textarea> to XML


Recommended Posts

Hello, 

I can't figure out how to write in an XML. 

I have an XML 

<line>
<text id="some-id"> some text I want to change </text>
  <other_elements/>
</line>

An XSLT - to get this HTML

<html>
  <head>
    <script/>
  </head>
<body>
  <textarea>TEXT I WANT TO SAVE</textarea> <!-- I write in it--> 
  <button onclick="function(id)">clic to save</button>
</body>

I want to "save" what I have written in the <textarea>in my XML to have

<line>
  <text id="some_id">TEXT I WANT TO SAVE</text>
  <other_elements/>
</line>

 

I don't know how to do it and as I work on only one XML I don't need to create a server... I just want the script to open the XML, change the text in the element, and close it.

 

thank's for the help 

P.  

Link to post
Share on other sites

Due to security restrictions, browsers are unable to write to files on the computer. You can make a download prompt appear using a data URL.

This code generates a download prompt for an XML file with specific contents:

<script>
var filename = "file.xml";
var content = "<?xml version='1.0' ?><element>XML code</element>";
var file = new File([content], filename, {type: "application/octet-stream"});
location.href = URL.createObjectURL(file);
</script>

I'm not sure if the original contents of an XSLT-transformed document are accessible to Javascript, but if they are, it should be simple enough to use DOM methods to modify the node you're looking for and then convert it into a string to be saved.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...