2012年8月28日星期二

xml转json

xml转json

function // Create the return object    var obj = {};    if (// element        // do attributes        if () {            obj["@attributes"] = {};            for (var j = 0; j < ) {                var attribute = "@attributes"][attribute.nodeName] = attribute.nodeValue;            }        }    } else if (// text        obj = // do children    if (for (var i = 0; i < ) {            var item = var nodeName = item.nodeName;            if (typeof (obj[nodeName]) == "undefined") {                obj[nodeName] = else {                if (typeof (obj[nodeName].length) == "undefined") {                    var old = obj[nodeName];                    obj[nodeName] = [];                    obj[nodeName].push(old);                }                obj[nodeName].push(return obj;};

TAG: