I need to create some case-sensitive XML nodes in JavaScript which have attribute names with a colon in between them.
Example: <Data ss:Type="String">Contact Name</Data>
When I try to create an element via JavaScript with the createElement() function it creates it in lowercase. Also, there are a lot of problems adding the attributes with a colon in them. For example: ss:Type="String"
This is Excel data, and I am saving the the source .xml file back to an .xls file. The case of the XML elements and attributes is very important for Excel to be able to read the file.
Any examples or pointers will be great help.
The JavaScript methods you are looking for are document.createElementNS and elm.setAttributeNS
var e = document.createElementNS('http://www.microsoft.com/office/excel/', 'Data');
e.setAttributeNS('http://www.microsoft.com/office/excel/', 'ss:Type', 'String');
e.textContent = 'Contact Name';
Then if you want to get strings back, .innerHTML won't work anymore so you have to use an XMLSerializer
var s = new XMLSerializer();
s.serializeToString(e);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With