国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

XmlUtils JS操作XML工具類

2024-05-06 14:13:42
字體:
來源:轉載
供稿:網友

demo用了點extjs的東西,主要是為了打印json數組出來。
js code(XmlUtils.js):
代碼如下:
/**/
function XmlUtils (config) {
/*定義私有屬性*/
this.isIE = !!(window.attachEvent && !window.opera);
this.init();
if(config) {
this.dataType = config.dataType == 'json' ? 'json' : 'array';
if(config.xmlPath) this.loadXml(config.xmlPath);
}
}
XmlUtils.prototype = {
xmlDoc : null,
xmlPath : null,
dataType : null,
/**
* 初始化
*/
init : function () {
if (this.isIE) {
var activexArr = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
for(i=0; i<activexArr.length; i++){
try{
this.xmlDoc = new ActiveXObject(activexArr[i]);
}catch(e){}
}
} else {
this.xmlDoc = document.implementation.createDocument("", "", null);
}
},

/**
* 加載xml文件,參數:
* @param {string} xmlPath:加載的xml文件路徑;
* @return {Object} true 正常加載; false 加載失敗
*/
loadXml : function (xmlPath) {
try {
this.xmlDoc.async = false;
this.xmlDoc.load(xmlPath);
this.xmlPath = xmlPath;
return true;
} catch (e) {
return false;
}
},

/**
* 加載XML字符串
* @param {Object} XMLString
*/
loadXmlString: function(xmlString) {
if (this.isIE) {
this.xmlDoc.loadXML(xmlString);
} else {
var parser = new DOMParser();
this.XMLDoc = parser.parseFromString(xmlString, "text/xml");
}
},

/**
* 判斷節點的是否有子節點
* @param {Object} node
* @return {Object} 有子節點則返回true,否則返回false
*/
hasChildNodes : function (node) {
return node.hasChildNodes();
},

/**
* 判斷節點的是否有屬性
* @param {Object} node
* @return {Object} 有屬性則返回true,否則返回false
*/
hasAttributes : function (node) {
return (node.attributes.length > 0) ? true : false;
},

/**
* 判斷節點的是否是文本節點,包括帶CDATA區段的文本節點
* @param {Object} node
* @return {Object} 是文本節點則返回true,否則返回false
*/
isTextNode : function (node) {
var type = this.getNodeType(node);
return (type == 3 || type == 4) ? true : false;
},

/**
* 返回根節點
* @return {Object} 根節點
*/
getRoot : function () {
return this.xmlDoc.documentElement;
},

/**
* 返回節點的第一個子節點,沒有參數則返回根節點的第一個子節點
* @param {Object} node
* @return {Object} 節點的第一個子節點
*/
getFirstChild : function (node) {
return node ? node.firstChild : this.getRoot().firstChild;
},

/**
* 返回節點的最后子節點,沒有參數則返回根節點的第一個子節點
* @param {Object} node
* @return {Object} 節點的最后一個子節點
*/
getLastChild : function (node) {

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 湛江市| 闽清县| 安平县| 铜山县| 苍梧县| 崇信县| 花莲市| 镇沅| 都匀市| 娄底市| 东源县| 南靖县| 靖州| 西平县| 唐海县| 桂东县| 历史| 鄱阳县| 民勤县| 大丰市| 日土县| 锡林郭勒盟| 奉节县| 高阳县| 宁阳县| 会泽县| 额敏县| 隆尧县| 青浦区| 三明市| 大同县| 天祝| 宜宾县| 资源县| 上饶县| 视频| 鞍山市| 兴文县| 乐都县| 岱山县| 普安县|