- 浏览: 1394726 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (328)
- JSF (27)
- 生活 (12)
- Ajax (26)
- Maven (6)
- CSS (1)
- Shale (3)
- SiteMesh (1)
- Ext (15)
- JMX (2)
- Windows技巧 (7)
- 工作感悟 (18)
- SVN (2)
- SVG (0)
- GoogleGear (0)
- RAP (2)
- SOA与WebService (3)
- 笔记本技术研究 (1)
- Microsoft (2)
- 英语学习 (3)
- PHP (7)
- web 2.0 (6)
- 语义Web (1)
- IT史话 (3)
- iText (3)
- JVM (1)
- PropertiesEditor (1)
- J2SE (33)
- Spring (2)
- Java Batch (1)
- log (2)
- Struts2 (2)
- DWR (0)
- JAAS (3)
- EJB3 (4)
- Flex (8)
- JFreeChart (1)
- WAS (0)
- 数据库 (2)
- 摄影 (0)
- SQL (1)
- Google App Engine (1)
- linux (5)
- Eclipse plugin (10)
- Testing (0)
- Portal (0)
- 移动互联网 (0)
- SWTBot (1)
最新评论
-
江奇缘:
不错!!!!!!
web.xml里<filter-mapping>中的<dispatcher>作用 -
yy8093:
commonj 第三步,那个调用的方法要在哪里调?servle ...
JAVA中多种计时器的比较与分析 -
di1984HIT:
学习了,不错~
web.xml里<filter-mapping>中的<dispatcher>作用 -
penkee:
com.lowagie.text.DocumentExcept ...
iText中输出 中文 -
氵壞男亼乀:
我想请问下 你哪个html里面引入的几个js文件没看懂!你 ...
DWR入门教程之HelloWorld
Dissecting DOM
Bill Venners : What's wrong with DOM?
Elliotte Rusty Harold : There's a phrase, "A camel is a horse designed by committee." That's a slur on a camel. A camel is actually very well adapted to its environment. DOM, on the other hand, is the sort of thing that that phrase was meant to describe.
DOM was designed by committee for many different purposes. It had to work for HTML and XML. It had to work for JavaScript in web browsers and traditional programming languages running on servers. It had to support many different languages: Java, C, C++, JavaScript, AppleScript, Perl, Python, Rexx—and for all I know, INTERCAL. The committee that designed DOM was trying to do all these things. Within the constraints that they were operating under, they failed.
DOM is incredibly complex. It is full of gotchas.
DOM's Gotchas
Bill Venners : What's are some of DOM's gotchas?
Elliotte Rusty Harold : Take namespaces, for example. There are two basic models for handling namespaces in an XML API. In one model, you assign each element and attribute a certain namespace, and you figure out where the namespace declarations need to go when you serialize the document. In the other model, you don't provide any special support for namespaces—you just treat the namespaces as attributes. That also works, although it's harder on the end user. DOM is the only API I know of that does both, simultaneously. DOM requires client programmers to understand and use both models. Otherwise they'll produce namespace-malformed documents, which is truly evil. DOM has all the complexity of both approaches and the simplicity of neither.
There are a lot of other issues with DOM that stem from its cross-language
nature. For example, DOM defines exactly one exception,
DOMException
, which has short
type codes to
indicate which kind of exception it is. To a Java programmer, this is just plain
weird. Java programmers use many different exception classes, and never
use short
s for anything. When was the last time you used a
short
in code? Have you ever? I don't think I've ever used
short
, except when I was trying to demonstrate all the data
types. But using a short
makes sense from a C or C++
programming perspective, where shorts are more common, and having many
exception types is not.
Some of the languages DOM needs to support, especially JavaScript, did not
support method overloading at the time DOM was invented. Therefore, DOM
could not have two methods such as createElement
, one that
takes an element name and a namespace, and another that takes only a local
name. Instead, DOM has createElement
, which takes
just the name, and createElementNamespace
, which takes
both a name and a namespace. There are many non-overloaded methods in
the DOM API that, to any Java or C++ programmer, should clearly be
overloaded.
There are several other DOM design decisions that confuse people.
For example, DOM trees do not allow nodes to be
detached from their parent document. Only the document that created the
node is allowed to hold the node. Also, DOM's DocType
object is read-only. Why? I can't explain these design decisions. I just know that
they are painful when you're actually trying to get work done with DOM.
Learning from DOM
Bill Venners : What did you learn from DOM? What things did they do that you thought made sense?
Elliotte Rusty Harold
: The single biggest lesson from DOM that comes
to mind is that polymorphism is good. It's very useful to have a
Node
interface or class, which all parts of the XML tree
extend in some fashion. Often you just want to walk the tree
and work with all the Node
s. You don't care whether a
Node
is an Element
, a Comment
,
a ProcessingInstruction
—you don't need that more specific type. DOM works very well
in those cases.
Bill Venners
: What kind of processing can you do with a
Node
irrespective of its more specific type?
Elliotte Rusty Harold : You can merge two documents, for example. You want to select this portion of document A, and copy it into this element of document B. You just want to walk down the tree of document A, and copy each node in the tree into document B.
Bill Venners : One thing you said you learned from DOM is that interfaces are a bad idea. Why?
Elliotte Rusty Harold : I learned that partially from DOM. DOM is designed around interfaces, rather than concrete classes, because it is written in IDL and needs to be compiled to many different programming languages. It relies on the abstract factory design pattern to actually form documents and DOM implementations.
A large part of the trouble of getting started with DOM is learning to work with the interfaces, rather than directly with the classes. If you look at the code many XML novices write with DOM, you'll see it is littered with the implementation classes of the specific DOM implementation, such as Xerces or Crimson.
To some extent mentioning implementation classes is unavoidable, because
DOM is incomplete. The Document
class serves as an abstract
factory for creating Element
objects, Comment
objects, Text
objects, and so forth. The DOM implementation
class is an abstract factory, which is used to create Document
and DocType
objects. However, they left out the part of the
abstract factory design pattern, where there's a static method that lets you load
the factory itself. You can't load the factory in DOM without using
implementation-specific classes. Overall, I just saw that the interfaces were
making life more difficult than it needed to be for a lot of programmers.
Bill Venners : You also said that you learned from DOM that successful APIs must be simple.
Elliotte Rusty Harold : Yes, although I suppose DOM is the reverse of that. DOM proves that a complex API is not likely to be successful, at least if it's substantially more complex than what it's trying to model.
发表评论
-
百万级访问量网站的技术准备工作
2010-12-29 19:35 1462当今从纯网站技术上来说,因为开源模式的发展,现在建一个小 ... -
Java EE Productivity Report 2011
2010-12-21 17:02 1634What happens when over 1000 J ... -
java.util.prefs.Preferences 简介
2010-04-23 14:07 4475Version 0.2 Cop ... -
An Introduction to LDAP
2010-04-13 16:24 1045An Introduction to LDAP Mich ... -
Java Interface 是常量存放的最佳地点吗?
2009-08-21 18:21 1261由于java interface中声明 ... -
Java的内存泄漏
2009-08-20 22:50 1294Java是如何管理内存 为了判断Java中是否有内 ... -
Transform XML into HTML using XSLT
2009-08-20 12:14 1828[howto.xml] <?xml versio ... -
eclipse 无法启动 JVM terminated. Exit code=-1
2009-08-09 13:52 2467eclipse 无法启动 JVM terminated. ... -
SDO ,WorkMananger,CommonJ overview
2009-07-06 10:51 1305Service Data Objects (SDO) -- P ... -
JAVA中多种计时器的比较与分析
2009-07-06 10:34 24095介绍 计时器可以提供运行基于时间的工作任务的功能,在计时器的管 ... -
Apache common io overview
2009-07-05 20:28 3875Apache 里面包含了太多有用的项目,值得我们仔细研究。恰当 ... -
Hashtable和HashMap的区别 Vector、ArrayList和List的异同(笔记)
2009-07-04 08:10 1903Hashtable和HashMap的区别:1.Hashtabl ... -
Java: System Properties
2009-05-25 11:10 2046From System Properties you ca ... -
SSL证书转换
2009-05-18 17:33 8514PKCS 全称是 Public-Key Cryptogra ... -
Keystores and Truststores
2009-05-18 14:39 2660Keystores and Truststores ... -
google app engine 是什么?
2009-04-08 18:50 3244Google是个真正能不断的 ... -
如何输入版权符号 copyright
2009-04-08 13:21 12277Unicode Character 'COPYRIGH ... -
深入浅出URL编码
2009-04-05 13:31 1119版权声明:如有转载请 ... -
Java IO一览
2009-04-04 12:23 1679对于我们常用的GBK中,英文是占用1个字节,中文是2个 对于 ... -
字节流与字符流的区别
2009-04-04 12:13 15097最近在项目中遇到一个encoding的问题,记录一下。 ...
相关推荐
《使用Ajax, APIs和库进行DOM编程之加速篇》是一本2007年的图书,主要探讨了如何高效地利用Ajax、APIs以及各种库来优化DOM(文档对象模型)编程。这本书对于深入理解Web开发中的动态交互和前端性能提升具有重要的...
《深入解析XML-apis.jar与org.w3c.dom.bootstrap.DOMImplementationRegistry类》 XML-apis.jar是Java开发中一个非常重要的库文件,它包含了处理XML(可扩展标记语言)的标准API,是Java处理XML文档的基础。这个库...
Word APIs 是一组编程接口,允许开发者通过编程方式与Microsoft Word应用程序进行交互,创建、修改、格式化和操作Word文档。这些APIs广泛应用于自动化办公流程、文档生成、报告编写等多种场景,极大地提高了工作效率...
xml-apis现在,为了方便大家学校Java,我现在上传一系列Java包,这些都是大家经常用到的,放心下载。这一系列材料,大家可以上我的资源库下载。
DOM4J是一个强大的Java库,专门用于处理XML文档。它提供了简单而灵活的API,使得在Java应用程序中读取、写入、修改以及查询XML变得容易。本篇将深入讲解DOM4J解析XML的原理与实践,同时提供相关源代码供参考。 一、...
xml-apis-2.0.2.jar 是一个专门处理XML相关操作的Java库,它是ECIDE(Enterprise Content Interaction Development Environment,企业内容交互开发环境)的依赖包之一。ECIDE可能是一个用于构建企业级应用的集成开发...
- **DOM(Document Object Model)**:提供了一种树形结构来表示XML文档,使得可以方便地通过Java对象模型来操作XML内容。 - **SAX(Simple API for XML)**:是一种基于事件驱动的XML解析器,适用于处理大型XML文档...
`xml-apis.jar` 是一个Java库,包含了处理XML相关操作的基础API,是许多Java开发人员在处理XML时不可或缺的依赖。这个库包含了多个XML规范的API实现,比如DOM(Document Object Model)、SAX(Simple API for XML)...
android的普通安装方法...google_apis-8_r02.zip (文件较大,分为4部分) google_apis-8_r02.part1.rar google_apis-8_r02.part2.rar google_apis-8_r02.part3.rar google_apis-8_r02.part4.rar 也可到以下地址下载: ...
标题“Accelerated DOM Scripting with Ajax APIs and Libraries”明确指出本书的主要内容是关于如何利用Ajax技术及其相关的API和库来加速DOM(Document Object Model)的脚本编程。DOM是一种用于HTML和XML文档的...
"xml-apis.jar" 是一个包含XML API实现的Java归档文件,它提供了处理XML文档所需的核心接口和类。这个JAR文件通常包含了对XML 1.0规范的支持,可能还包含了对XPath、XSLT和DOM等XML相关技术的API。 1. **XML API**:...
xml-apis.jar xml-apis.jar
The popularity of REST in recent years has led to tremendous growth in almost RESTful APIs that don’t include many of the architecture’s benefits With this practical guide you’ll learn what it ...
APIS,全称为Advanced Passenger Information System,即高级旅客信息系统,是一个国际间通用的规定,要求航空公司或其代理在航班起飞前提供乘客的特定信息,用于边境安全和移民控制。 这篇文档可能详细介绍了ETERM...
xml-apis-ext.jar,hightcharts导出图片是解决乱码需要用到的一个包
清单如下: dom4j-1.6.1.jar ...xml-apis-2.0.2.jar xpp3-1.1.3.3.jar xsdlib-20030807.jar 从GitHub上下载下来的,CSDN这资源分设置...恩,算了,没积分的自己去下载吧: https://dom4j.github.io/ ...