判断是否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>
<
相关文档:
收藏
我曾在前面介绍过一个可用于BREW环境下的XML Parser,今天想分享的是如何在Symbian平台上解析XML文件,不需要第三方的东西,Symbian已经为我们提供了这个类CParser。
网上也有这方面的资料,建议参考:
http://wiki.forum.nokia.com/index.php/How_to_parse_XML_file_using_CParser_class
不过,要注意的是Symbia ......
Reviewer Approved
The following example shows how to parse XML file using Symbian OS C++ class, CParser. CParser is basically a SAX (Simple API for XML)-based XML parser.
It uses an active object to read the XML file chunk by chunk (see CXmlHandler::StartParsingWithAoL( ......
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 ......
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"
>
......
关于安装multiget出现XML::Parser perl module is required for intltool错误问题的解决 收藏
在安装Multiget,在configure的时候提示XML::Parser perl module is required for intltool错误。具体解决的方法如下: #perl -MCPAN -e shell 之后跟据提示一步步往下,配置完后会出现一个 >的命令提示 >install ......