TPK wrote:
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.imple mentation && typeof
document.implem entation.create Document != 'undefined') {
xmlDocument = document.implem entation.create Document('', 'dummy', null);
}
else if (typeof ActiveXObject != 'undefined') {
try {
xmlDocument = new ActiveXObject(' Msxml2.DOMDocum ent');
}
catch (e) {
try {
xmlDocument = new ActiveXObject(' Microsoft.XMLDO M');
}
catch (e) {}
}
}
if (xmlDocument != null) {
var root = xmlDocument.cre ateElement('god s');
if (xmlDocument.do cumentElement) {
xmlDocument.rep laceChild(root, xmlDocument.doc umentElement);
}
else {
xmlDocument.app endChild(root);
}
var god = xmlDocument.cre ateElement('god ');
god.appendChild (xmlDocument.cr eateTextNode('K ibo'));
root.appendChil d(god);
if (typeof XMLSerializer != 'undefined') {
alert(new XMLSerializer() .serializeToStr ing(xmlDocument ));
}
else {
alert(xmlDocume nt.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.DOMDocum ent') (respectively new
ActiveXObject(' Microsoft.XMLDO M')) is for IE/Win using MSXML to create
an XML DOM document which is empty.
--
Martin Honnen
http://JavaScript.FAQTs.com/