Tags

, , , ,

Web service list.asmx is deprecated, but somehow it seems to be the only way to obtain the desired results. For example, I am not aware of any other way to expand recurrence from an event list using client side code. So, in case you are required to use it, here is how you can obtain an array of objects from XML sent back by the web service.

function parseResponse(xmlResponse) {
    /// <summary>Obtain an array of objects from server responseXML</summary>
    /// <param name="xmlResponse"></param>
    /// <returns type="Array"></returns>


    var items = new Array();
    var rows = (typeof (xmlResponse.getElementsByTagNameNS) === 'undefined') ? xmlResponse.getElementsByTagName("z:row") : xmlResponse.getElementsByTagNameNS("*", "row");

    for (var i = 0; i < rows.length; i++) {
        var row = rows.item(i);
        var item = new Object();
        for (var j = 0; j < row.attributes.length; j++) {
            var currentNodeName = row.attributes[j].nodeName.replace('ows_', '');
            var currentNodeValue = row.attributes[j].nodeValue;
            if ((currentNodeValue == undefined) || (currentNodeValue == null)) {
                item[currentNodeName] = '';
            }
            else {
                item[currentNodeName] = currentNodeValue;
            }
        }
        items.push(item);
    }
    return items;
}

The function worked for me in Chrome, IE11 and Firefox. However, it seems “nodeValue” is a deprecated property, is still working, but it should be replaced with “value” property to avoid possible future problems.

Advertisements