Improvement (?) for poorly-behaved web services

Topics: Developer Forum
Nov 16, 2006 at 4:33 PM
First, excellent work.
Second, in using code against the GetQuotes service here:

I noticed a problem. If the WS returns a sequence of objects that all have the same name (as GetQuotes does, a sequence of StockQuote), the _node2object method will only wind up storing the last one, since it will overwrite all previous. This is silly on the part of the web service provider - it should be an array. However, to "correct" the code to work around this problem, I put together the following change, thought I'd share. You can probably do much better than this =)
for(var i = 0; i < node.childNodes.length; i++)
var p = SOAPClient._node2object(node.childNodesi, wsdl);
//don't want to overwrite in the case of a sequence of multiple objects with the same name
//if the object already has one, we will store it and switch to an array
//if it's already an array, we will append to the end
if (typeof(objnode.childNodes[i].nodeName)!='undefined')
var old = objnode.childNodes[i].nodeName;

if (old instanceof Array)
objnode.childNodes[i].nodeName = new Array();
objnode.childNodes[i].nodeName0 = old;
objnode.childNodes[i].nodeName1 = p;
objnode.childNodes[i].nodeName = p;