Symbian WRT中使用JS自动将XML、JSON转换成为对象
2010-08-30 00:03:00 来源:WEB开发网var nodeName = option['nodeName'];
//取得节点元素
var da = items[i].getElementsByTagName(nodeName)[0];
//通过options取得对应的成员变量名称
var memberName = option['memberName'];
var nodeValueOrAttribute = option['nodeValueOrAttribute'];
var attributeName = option['attributeName'];
if (da != null || da != undefined) {
//判断是取节点的值还是其中的属性值
if (nodeValueOrAttribute == 'attribute' &&
(attributeName != undefined || attributeName != null)) {
selfProcessData.data1.putProperty(memberName, da.getAttribute(attributeName));
}
else {
if (da.firstChild == null || da.firstChild == undefined) {
selfProcessData.data1.putProperty(memberName, null);
}
else {
selfProcessData.data1.putProperty(memberName, da.firstChild.nodeValue);
}
}
}
else {
selfProcessData.data1.putProperty(memberName, null);
}
}
array[i] = selfProcessData.data1;
}
selfProcessData.processDataFunction(array);
}
/**
* 构造方法
* @param {Object} Url xml JSON地址
* @param {Object} parentNode 父节点,比如要把
* @param {Object} options
* @param {Object} processDataFunction ???象弈?完成后需要整用的方法
*/
function ProcessData(Url, parentNode, options, processDataFunction){
this.URL = xmlUrl;
this.parentNode = parentNode;
this.options = options;
this.processDataFunction = processDataFunction;
selfProcessData = this;
}
ProcessData.prototype = new Object();
ProcessData.prototype.URL;
ProcessData.prototype.options;
更多精彩
赞助商链接