易截截图软件、单文件、免安装、纯绿色、仅160KB

判断是否XML文档

xhtml的昙花一现带来不少问题,它的目的是让html表现得更像xml,所以才叫xhtml。但是出师未捷身先死,我们讨论一下如何判定文档是XML吧。
印象中jQuery对此方法重复实现了许多次,应该比较权威,也说明这判定比较难搞。看jQuery1.42的实现:
var isXML = function(elem){
// documentElement is verified for cases where it doesn't yet exist
// (such as loading iframes in IE - #4833)
var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
return documentElement ? documentElement.nodeName !== "HTML" : false;
};
好,做一个实验:
window.onload = function(){
try{
var doc = document.implementation.createDocument(null, 'HTML', null);//只限标准浏览器,创建一个XML文档
alert(doc.documentElement)
alert(isXML(doc))//应该返回true
}catch(e){
alert("不支持creatDocument方法")
}
}


<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="IE=8" http-equiv="X-UA-Compatible"/>
<title>判断是否为XML by 司徒正美 </title>
<script type="text/javascript">
var isXML = function(elem){
var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
return documentElement ? documentElement.nodeName !== "HTML" : false;
};
window.onload = function(){
try{
var doc = document.implementation.createDocument(null, 'HTML', null);
alert(doc.documentElement)
alert(isXML(doc))
}catch(e){
alert("不支持creatDocument方法")
}
}
</script>
</head>
<body>
</body>
</html>

运行代码
另一个实验:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<


相关文档:

Example Code of Using XML Parser in Symbian OS

antonypr | 14 April, 2007 00:05
A couple of weeks ago, I had a plan to write an article and example code of using XML parser in Symbian OS. It seems that another Forum Nokia Champion, Paul Todd had the same idea. He posted a nice article about XML parser in Symbian OS 9.x to Forum Nokia Blogs. It's ......

xml 安装bug

[Bug 230608] missing config.h in latest -14
Ralf Corsepius rc040203 at freenet.de
Tue Mar 6 13:31:13 UTC 2007
Previous message: [Bug 230608] missing config.h in latest -14
Next message: [Bug 230608] missing config.h in latest -14
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] ......

XML字符串和XML DOCUMENT的相互转换

本文涉及到XML字符串和Xml Document的转换问题,就各种XML解析器分别列举如下,以方便今后查阅。
  一、使用最原始的javax.xml.parsers,标准的jdk api
  // 字符串转XML
  String xmlStr = \"......\";
  StringReader sr = new StringReader(xmlStr);
  InputSource is = new InputSource(sr);
  Doc ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号