论坛首页 入门技术论坛

页面ext与xml

浏览 1753 次
锁定老帖子 主题:页面ext与xml
该帖已经被评为新手帖
作者 正文
   发表时间:2008-09-27  
// 根据xml创建dom对象
function loadXMLString(xmlString) {
  var xmlDoc = null;
  try {
    var parser = new DOMParser();
    xmlDoc = parser.parseFromString(xmlString, "text/xml");
  } catch (e) {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.loadXML(xmlString);
  }
  return xmlDoc;
}

/**
* 组织成例子grid3一样的数据其中为json格式,然后需要eval作为Store的data
*/
function getStoreData(xmlStr) {
var xmlDoc = loadXMLString(xmlStr);
var returnStr = "[";
var con = xmlDoc.getElementsByTagName("relation");
for (var i = 0; i < con.length; i++) {
var relation = con[i];
returnStr += "[";
var relationChilds = relation.childNodes;
for (var j = 0; j < 5; j++) {
var relationChild = relationChilds[j];
returnStr += "'";
returnStr += relationChild.text;
returnStr += "'";
if (j != 4) {
returnStr += ",";
}
}
returnStr += "]";
if (i != (con.length - 1))
returnStr += ",";
}
returnStr += "]";
return returnStr;
}
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics