Create XML using JS and convert to string

jessieviolet

New Member
I'm trying to convert form values into XML.The whole script worked fine in Chrome etc, but IE8 had to ruin it, of course. I first had to change my code because IE was throwing errors on the append function (apparently I had created HTML elements instead of XML elements. So now I think it's all XML and IE is not whining anymore. However, when I'm trying to convert the XML to a string, both Chrome and IE return undefined (chrome actually shows a blank line in the console.What am I doing wrong?\[code\] function xmlToString(xmlData) { var xmlString; //IE if (window.ActiveXObject){ xmlString = xmlData.xml; } // code for Mozilla, Firefox, Opera, etc. else{ xmlString = (new XMLSerializer()).serializeToString(xmlData); } return xmlString;} function saveValues(thisB,formName){ var xpath = $(thisB).attr("xpath"); var returnToServer = $(thisB).attr("returnToServer"); var version = $(thisB).attr("version"); var now= Math.round(new Date().getTime() / 1000) var $root = $($.parseXML("<XMLDocument />").getElementsByTagName('*')[0]); var $valuesEl = $($.parseXML('<saveValues xpath="'+xpath+'" returnToServer="'+returnToServer+'" version="'+version+'"></saveValues>').getElementsByTagName('*')[0]); $("input").each(function(){ var name = $(this).attr("name"); if(name != 'xmlToPost'+formName && name != 'saveValuesButton'){ if( $(this).attr("type") == 'text' || (($(this).attr("type") == 'checkbox' || $(this).attr("type") == 'radio') && $(this).is(":checked"))){ $valueEl = $($.parseXML('<value datetime="'+now+'" version="'+version+'" name="'+name+'"></value>').getElementsByTagName('*')[0]); $valuesEl.append($valueEl); } } }); $root.append($valuesEl); var valuesXML = xmlToString($root); var postToXMLContent = $("#xmlToPost"+formName).val(); valuesXML = valuesXML.replace(/savevalues/gi,"saveValues"); valuesXML = valuesXML.replace("returntoserver","returnToServer"); //..rest of code }\[/code\]When I log the $root object, Chrome gives me a big object that starts with \[code\][<xmldocument>, context: <xmldocument>]\[/code\], which I can expand to find childnodes, that contains saveValues etc. IE just shows \[code\][object Object]\[/code\].
 
Back
Top