TPK said:
Is there any way javascript can be used to assemble a XML file?
Any resources out there that may explain how to do this (if possible)?
You can use the DOM to build an in memory XML DOM document. Saving to a
local file is usually (meaning in the browser sandbox) not possible but
you can use XMLHttpRequest so send such a DOM document to your server.
var xmlDocument = null;
if (document.implementation && typeof
document.implementation.createDocument != 'undefined') {
xmlDocument = document.implementation.createDocument('', 'dummy', null);
}
else if (typeof ActiveXObject != 'undefined') {
try {
xmlDocument = new ActiveXObject('Msxml2.DOMDocument');
}
catch (e) {
try {
xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
}
catch (e) {}
}
}
if (xmlDocument != null) {
var root = xmlDocument.createElement('gods');
if (xmlDocument.documentElement) {
xmlDocument.replaceChild(root, xmlDocument.documentElement);
}
else {
xmlDocument.appendChild(root);
}
var god = xmlDocument.createElement('god');
god.appendChild(xmlDocument.createTextNode('Kibo'));
root.appendChild(god);
if (typeof XMLSerializer != 'undefined') {
alert(new XMLSerializer().serializeToString(xmlDocument));
}
else {
alert(xmlDocument.xml);
}
}
createDocument is W3C DOM Level 2 Core to create an XML DOM document.
That method wants the tag name (and namespace) of the root element so
the newly created document has already a root element. The method is
supported by browsers like Mozilla/Firefox, Opera 8/9.
new ActiveXObject('Msxml2.DOMDocument') (respectively new
ActiveXObject('Microsoft.XMLDOM')) is for IE/Win using MSXML to create
an XML DOM document which is empty.