javascript Xml兼容性随笔
一、前言
(function (window) {
if (!window.jasen) {
window.jasen = {};
} if (!window.jasen.core) {
window.jasen.core = {};
} //------------------------------------------------
// XML operation below.
//------------------------------------------------
if (!window.jasen.core.Xml) {
window.jasen.core.Xml = {};
} if (typeof jasen.core.Xml != "object") {
throw new Error("Invalid entity jasen.core.Xml!");
} function createXmlDocument() {
//IE
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLDOM");
}
//W3C
else if (document.implementation && document.implementation.createDocument) {
return document.implementation.createDocument('', '', null);
} throw new Error("Xml is not supported by your brower!");
} function loadXmlFile(xmlFile) {
var xmlDocument = createXmlDocument();
xmlDocument.async = false;
xmlDocument.load(xmlFile);
return xmlDocument;
} function loadXmlText(xmlText) {
// IE Must be tested first if (window.ActiveXObject) {
var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
xmlDocument.async = false;
xmlDocument.loadXML(xmlText); return xmlDocument;
}
// W3C
else if(window.DOMParser) {
return (new DOMParser()).parseFromString(xmlText, "text/xml");
} throw new Error("Xml is not supported by your brower!");
} var Xml = window.Xml = window.jasen.core.Xml;
Xml.createDocument = createXmlDocument;
Xml.loadFile = loadXmlFile;
Xml.loadText = loadXmlText; })(window);
二、范例
<script language="javascript" type="text/javascript">
function testXml() {
var xmlDoc = Xml.loadFile("/Xml/House.xml");
var xmlDocElement = xmlDoc.documentElement;
var nodes = xmlDocElement.getElementsByTagName("city");
var currNode = null; for (var i = 0; i < nodes.length; i++) {
currNode = nodes[i]
} var xmlText = "<address><city name='北京'><price>150万</price><type>一室三居</type></city></address>";
xmlDocElement = Xml.loadText(xmlText); var cityName = xmlDocElement.selectSingleNode("address/city/@name").nodeValue;
var price = xmlDocElement.selectSingleNode("address/city/price/text()").nodeValue;
}
</script>
javascript Xml兼容性随笔的更多相关文章
- javascript opacity兼容性随笔
一.CSS兼容代码 .transparent { filter:alpha(opacity=50); /* IE */ -moz-opacity:0.5; /* FireFox old version ...
- javascript event兼容性随笔
一.前言 function ConvertEvent(e, element) { var event = e || window.event; var resultEvent = { event: e ...
- javascript position兼容性随笔
一.Javascript源码 if (!window.jasen.core.Position) { window.jasen.core.Position = {}; } function Size(w ...
- 《高性能javascript》 领悟随笔之-------DOM编程篇(二)
<高性能javascript> 领悟随笔之-------DOM编程篇二 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...
- 《高性能javascript》 领悟随笔之-------DOM编程篇
<高性能javascript> 领悟随笔之-------DOM编程篇一 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...
- 转 创建 JavaScript XML 文档注释
http://www.cnblogs.com/chenxizhang/archive/2009/07/12/1522058.html 如何:创建 JavaScript XML 文档注释 Visual ...
- JavaScript & XML
原文:JavaScript & XML 检测浏览器能力特性 //检测浏览器是否支持DOM2级XML var hasXmlDom = document.implementation.hasFea ...
- JAVASCRIPT 浏览器兼容性问题及解决方案列表
JAVASCRIPT 浏览器兼容性问题及解决方案列表(1)获取HTML元素只兼容IE:document.all.hello hello 兼容所有: document.getElementById(“h ...
- JavaScript 事件兼容性写法
1.以下是JavaScript事件兼容性写法,使用者可以随意使用,兼容所有浏览器.包括IE6(亲测) <!DOCTYPE html> <html> <head> & ...
随机推荐
- 【待整理】Linux故障排查
ethtool -i eth0dmidecode -i eth3more /var/log/meclogmore /etc/issue
- Create side-by-side stereo pairs in the Unity game engine
Create side-by-side stereo pairs in the Unity game engine Paul BourkeDecember 2008 Sample Island pro ...
- django搭建论坛之一环境配置
环境情况: Description: Ubuntu 15.04 Python版本: Python 2.7.9 django版本: 1.8.4 安装django: pip install ...
- My安卓知识4--Media Player called in state 0
//根据被传递的歌曲名称,选择播放的歌曲 public void playByName(String name){ mp = new MediaPlayer(); t ...
- lphp输出控制output controll(header, ob_xxx)
关于php的output controll参考文档: http://gywbd.github.io/posts/2015/1/php-output-buffer-in-deep.html http:/ ...
- iis 500.19错误解决过程记录
前段时间一直在纠结C#中,dll的管理问题.最后选择使用nugetgallery进行公共库管理.项目地址:https://github.com/NuGet/NuGetGallery.这是一个nuget ...
- Java String字符串方法
1.String构造函数 1> String() 2> String(char[] chars) String(char[] chars,int startIndex,int numCha ...
- css3动画之图片旋转
直接上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Centos 7下mysql的安装与配置
1,先下载好MySQ安装包并解压(不做详细说明). 2,上传解压后的MySQL安装包到虚拟机上. 3,安装MySQL [root@localhost /]# yum install mysql5.7. ...
- Java学习笔记 04 类和对象
一.类和对象的概念 类 >>具有相同属性和行为的一类实体 对象 >>实物存在的实体.通常会将对象划分为两个部分,即静态部分和动态部分.静态部分指的是不能动的部分,被称为属性,任 ...