易截截图软件、单文件、免安装、纯绿色、仅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>
<


相关文档:

交换数据学习一:将xml文本读取到DataSet并显示

//xml文档内容
<?xml version = "1.0" encoding="gb2312" standalone="yes"?>
<VFPData>
 <company>
  <companyno>100</companyno>
  <companyname>上海</companyname>
  <ceoname>陈四</ceoname>
  <ceoma ......

Symbian OS下解析XML文档的一些方法

2009-10-27 22:44资料来源于网络,四种方式,大家可以自己尝试下.
=========11111=================
tinyXML
www.grinninglizard.com/tinyxml/
=========22222================================
symbian s60 第三版之后,已经提供了解析xml的系统api,采用的是SAX方式。
XML parsing in Symbian OS v9.x 来源目录:
htt ......

Symbian学习笔记(15) 解析XML文件(上)

收藏
我曾在前面介绍过一个可用于BREW环境下的XML Parser,今天想分享的是如何在Symbian平台上解析XML文件,不需要第三方的东西,Symbian已经为我们提供了这个类CParser。
网上也有这方面的资料,建议参考:
http://wiki.forum.nokia.com/index.php/How_to_parse_XML_file_using_CParser_class
不过,要注意的是Symbia ......

Use the XML Parser in OS 9.x


Paul.Todd | 09 April, 2007 15:24
I have noticed a couple of people seem to be having problems with using the XML parser in Symbian and there are no examples outside of the devkit. The parser I will be talking about is the xml one, not the one SOAP engine as the SOAP one is Nokia specific.
The ke ......

Android拍照上传程序的xml配置文件

1. login_window.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_logo"
>
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号