/******************************************************************************
说明:xml解析类
******************************************************************************/ function XMLDOCDocument() {
this.xmlDoc = null;
this.async = false;
this.xml = null;
}; function createDocument() {
if (typeof arguments.callee.activeXString != "string") {
var versions = ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument"],
i, len;
for (i = 0, len = versions.length; i < len; i++) {
try {
new ActiveXObject(versions[i]);
arguments.callee.activeXString = versions[i];
ActiveXObject(arguments.callee.activeXString);
break;
} catch (ex) {
//跳过
}
}
}
return new ActiveXObject(arguments.callee.activeXString);
};
/*
描述:加载xml
*/
XMLDOCDocument.prototype.loadXML = function (xmlInfo) {
//判断浏览器的类型
//支持IE浏览器 var isLoad = false;
var xmlDomVersions = ['MSXML.2.DOMDocument.6.0', 'MSXML.2.DOMDocument.3.0', 'Microsoft.XMLDOM'];
for (var i = 0; i < xmlDomVersions.length; i++) {
try {
this.xmlDoc = new ActiveXObject(xmlDomVersions[i]);
this.xmlDoc.async = this.async;
this.xmlDoc.loadXML(xmlInfo); //loadXML方法载入xml字符串
this.xml = this.xmlDoc.documentElement.outerHTML;
isLoad = true;
break;
} catch (e) {
}
}
if (!isLoad) {
if (typeof DOMParser != "undefined") {
this.xmlDoc = (new DOMParser()).parseFromString(xmlInfo, "text/xml");
this.xml = this.xmlDoc.documentElement.outerHTML;
var errors = this.xmlDoc.getElementsByTagName("parsererror");
if (errors.length) {
throw new Error("XML parsing error:" + errors[0].textContent);
}
} else {
throw new Error("No XML parser available.");
}
}
}; /*
说明:选择所有符合条件的节点
*/
XMLDOCDocument.prototype.selectNodes = function (xPath) {
return this.xmlDoc.selectNodes(xPath);
};
/*
说明:选择一个符合条件的节点
*/
XMLDOCDocument.prototype.selectSingleNode = function (xPath) {
return this.xmlDoc.selectSingleNode(xPath);
}; /*
说明:创建新节点
*/
XMLDOCDocument.prototype.createElement = function (nodeName) {
return this.xmlDoc.createElement(nodeName);
}; /*
说明:创建新属性
*/
XMLDOCDocument.prototype.createAttribute = function (attrName) {
return this.xmlDoc.createAttribute(attrName);
};
/*
说明:获得xml字符串
*/
XMLDOCDocument.prototype.getXml = function () {
//return this.xmlDoc.xml;
if (typeof this.xmlDoc.xml != "undefined") { return this.xmlDoc.xml;
}
else if (typeof XMLSerializer != "undefined") {
return (new XMLSerializer()).serializeToString(this.xmlDoc);
} else {
throw new Error("Could not serialize XML DOM.");
}
};
/*
说明:获得xml字符串
*/
XMLDOCDocument.prototype.toString = function () {
//return this.xmlDoc.xml;
if (typeof this.xmlDoc.xml != "undefined") { return this.xmlDoc.xml;
}
else if (typeof XMLSerializer != "undefined") {
return (new XMLSerializer()).serializeToString(this.xmlDoc);
} else {
throw new Error("Could not serialize XML DOM.");
}
}; // check for XPath implementation
if (document.implementation.hasFeature("XPath", "3.0")) {
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function (cXPathString, xNode) {
if (!xNode) {
xNode = this;
}
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for (var i = 0; i < aItems.snapshotLength; i++) {
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}; // prototying the Element
Element.prototype.selectNodes = function (cXPathString) {
if (this.ownerDocument.selectNodes) {
return this.ownerDocument.selectNodes(cXPathString, this);
}
else {
throw "For XML Elements Only";
}
}; // prototying the XMLDocument
XMLDocument.prototype.selectSingleNode = function (cXPathString, xNode) {
if (!xNode) { xNode = this; }
var xItems = this.selectNodes(cXPathString, xNode);
if (xItems.length > 0) {
return xItems[0];
}
else {
return null;
}
}; // prototying the Element
Element.prototype.selectSingleNode = function (cXPathString) {
if (this.ownerDocument.selectSingleNode) {
return this.ownerDocument.selectSingleNode(cXPathString, this);
}
else { throw "For XML Elements Only"; }
} Element.prototype.__defineGetter__("innerText",
function () {
return this.textContent;
}
); Element.prototype.__defineSetter__("innerText",
function (sText) {
this.textContent = sText;
}
); };

js解析xml浏览器兼容性处理的更多相关文章

  1. js 解析XML 在Edge浏览器下面 无法准确读到节点属性值

    js 解析XML 在Edge浏览器下面 无法准确读到节点属性值 Dom.documentElement.childNodes[j].attributes[2]  这个是大众写法 在win10的edge ...

  2. JS解析XML文件和XML字符串

    JS解析XML文件 <script type='text/javascript'> loadXML = function(xmlFile){ var xmlDoc=null; //判断浏览 ...

  3. CSS控制XML与通过js解析xml然后通过html显示xml中的数据

    使用CSS控制XML的显示 book.css bookname{ display:block;color:Red} author{ display:block;font-style:italic} p ...

  4. js解析xml,获取XMl标签属性值

    <script type="text/javascript"> var xml="<?xml version=\"1.0\" enc ...

  5. node.js 解析xml BOM问题(xmlreader sax.js)

    Email:longsu2010 at yeah dot net 之前写了两篇文章关于node.js解析xml,说的是xmlreader,文章如下 node.js解析xml(xmlreader) no ...

  6. 用js解析XML文件,字符串一些心得

    解析XML文件遇到的问题 今天秦博士叫我解析一下XML文件,将里面的所有的X坐标Y坐标放在一个数组里面然后写在文档里让他进行算法比对,大家都知道了啦,解析XML文件获取里面的坐标数据什么的,当然是用前 ...

  7. JS 解析Xml

    loadXML = function (xmlString) { var xmlDoc = null; //判断浏览器的类型 //支持IE浏览器 if (!window.DOMParser & ...

  8. tab.js分享及浏览器兼容性问题汇总

    在 样式布局分享-基于frozen.js的移动OA 文章中,用了到第三方组件 tab.js(带菜单的横屏滑动插件),其兼容性很差,进行优化后,已兼容全平台(且支持IE6+). tab.js GitHu ...

  9. js解析XML

    //在当前页面内追加换行标签和指定的HTML内容function w( html ){    $(document.body).append("<br/>" + htm ...

随机推荐

  1. 关于C++编译链接和模板函数

    一,关于编译链接编译指的的把编译单元生成目标文件的过程链接是把目标文件链接到一起的过程编译单元:可以认为是一个.c或者.cpp文件.每个编译单元经过预处理会得到一个临时的编译单元.预处理会间接包含其他 ...

  2. 【luogu1220】关路灯

    https://www.luogu.org/problem/show?pid=1220 假如当前老张在a处跑去关掉b处的路灯,那么a与b之间的路灯都可以顺手关掉.因此每一时刻关掉的路灯必定是连续的. ...

  3. day1-Python入门

    百度云有关文档资料链接 链接:https://pan.baidu.com/s/1pLighnX 密码:j69s

  4. 项目实战12.2—企业级监控工具应用实战-zabbix操作进阶

    无监控,不运维.好了,废话不多说,下面都是干货. 流量党勿入,图片太多!!! 项目实战系列,总架构图 http://www.cnblogs.com/along21/p/8000812.html 一.U ...

  5. [转]addEventListener() 方法,事件监听

    转载  白杨-M  http://www.cnblogs.com/baiyangyuanzi/p/6627401.html addEventListener() 方法,事件监听 你可以使用 remov ...

  6. 设置两个div是总是不能重合,浏览器user agent stylesheet问题

    如图 两个div之间总是有一个空行,设置了margin为0还是没卵用,f12调试发现 多了一个user agent stylesheet样式,经百度是浏览器自带的样式 重新为div内的元素ul设置cs ...

  7. Django安装与开发虚拟环境搭建01

    Django是一款基于python的MVT的web开发框架(m表示model,主要用于对数据库层的封装  ,v表示view,用于向用户展示结果,c表示controller,是核心,用于处理请求.获取数 ...

  8. 微信小程序各类型的自定义组件篇

    由于本人最近在开发小程序项目,期间对小程序有花点时间去研究,同时也找了网上大牛的一些案例,在这里分享部分自定义组件,部分代码是copy大牛案例的,有对小程序有兴趣的伙伴拿走,不谢! 源码下载地址:ht ...

  9. 《HelloGitHub》第 21 期

    公告 元旦快乐! <HelloGitHub>第 21 期 兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 这是一个面向编 ...

  10. 《程序设计实践》【PDF】下载

    <程序设计实践>[PDF]下载链接: https://u253469.ctfile.com/fs/253469-231196319 内容简介 本书从排错.测试.性能.可移植性.设计.界面. ...