国产探花免费观看_亚洲丰满少妇自慰呻吟_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) {

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

圖片精選

主站蜘蛛池模板: 莱芜市| 庐江县| 顺义区| 北川| 老河口市| 林周县| 恩施市| 潼关县| 察哈| 兴城市| 乐亭县| 浦北县| 西林县| 吴桥县| 政和县| 灵石县| 白沙| 台北市| 沅陵县| 柏乡县| 璧山县| 南城县| 宜川县| 冀州市| 磐石市| 高密市| 乐业县| 巢湖市| 江西省| 芦溪县| 金坛市| 定西市| 富民县| 湖北省| 鲁山县| 洛扎县| 万年县| 通江县| 道孚县| 滕州市| 丰镇市|