I have an HTML table from which I want to record data into SQL database. I would like use a stored procedure for that. As of now, I am reading table into key/value object. I would like to use that object as parameter in SQL stored procedure. Its my understanding that the best way to do it, is to convert Javascript Object to XML. Which I can do using this:
function objectToXml(object) {
var xml = '';
for (var prop in object) {
if (!object.hasOwnProperty(prop)) {
continue;
}
if (object[prop] == undefined)
continue;
xml += "<" + prop + ">";
console.log(object[prop], prop, typeof prop)
if (typeof object[prop] == "object")
xml += objectToXml(new Object(object[prop]));
else
xml += object[prop];
xml += "</" + prop + ">";
}
return xml;
}
That function returns XML string in the following format:
<0><key1>value1</key1>....<keyN>valueN</keyN></0><1><key1>value1a</key1>....<keyN>valueNa</keyN></1>..
I can pass that string into SQL stored procedure but struggling after that. I would appreciate any guidance.