Skip to content
Advertisement

How to write an XML file with certain format using JS?

I am trying to write an XML document from an HTML form using JavaScript with the following function:

JavaScript function:

JavaScript

The file that is generated has the following format:

JavaScript

I am trying to modify the method in order for the nodes to have the following format:

JavaScript

I know that setAttribute() doesn’t work because it makes an attribute in the node. I can’t find a function that sets the value like the example above.

Any suggestions?

Advertisement

Answer

You can use the innerHTML attribute on the element to set the value.

JavaScript

Example output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement