CHAPTER 12 DOM LEVELS 2 AND 3 DOM CHANGES 的翻译

欢欢欢欢 发表于 2016-9-16 11:12

The purpose of the DOM Levels 2 and 3 Core is to expand the DOM API to encompass all of the requirements of XML and to provide for better error handling and feature detection. For the most part, this means supporting the concept of XML namespaces. DOM Level 2 Core doesn’t introduce any new types; it simply augments the types defined in DOM Level 1 to include new methods and properties. DOM Level 3 Core further augments the existing types and introduces several new ones.

翻译:

DOM Levels 2 和 3的内核是为了拓展DOM API来拥抱XML的所有需求以及提供更好的错误处理和属性检测的能力。要这么做,最主要的就是支持XML的命名空间概念。DOM Level 2 Core没有没有引入新的类型,只是简单的增强了DOM Level 1中已经定义的类型,让它们包含新了的方法和属性。DOM Level 3Core进一步增强了已经存在的类型,同时引入一些新的类型。

 

XML Namespaces

XML namespaces allow elements from different XML-based languages to be mixed together in a single, well-formed document without fear of element name clashes. Technically, XML namespaces are not supported by HTML but supported in XHTML; therefore, the examples in this section are in XHTML.

翻译:

XML命名空间允许来自不同的基于XML的语言的元素被混编的一起,形成一个单一的,有良好结构的文档而不用担心元素命名冲突。单从技术上讲,HTML不支持XML命名空间,XHTML才支持。因此这一章的示例都是基于XHTML。

 

The class attribute in this example is prefi xed with xhtml. Namespacing isn’t really necessary when only one XML-based language is being used in a document; it is, however, very useful when mixing two languages together. Consider the following document containing both XHTML and SVG:

翻译:

在这个示例中,class属性钱加一个了xhtml的前缀。当文档中只有一种XML语言的时候,命名空间前缀真的没有必要。然而当两种XML余元混用的时候,它还是非常有用的。看看下面这个同时包含了XHTML和SVG的文档:

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Example XHTML page</title>
</head>
<body>
<svg xmlns=”http://www.w3.org/2000/svg” version=”1.1”
viewBox=”0 0 100 100” style=”width:100%; height:100%”>
<rect x=”0” y=”0” width=”100” height=”100” style=”fi ll:red” />
</svg>
</body>
</html>
 
 
In this example, the element is indicated as foreign to the containing document by setting its own namespace. All children of the element, as well as all attributes of the elements, are considered to be in the http://www.w3.org/2000/svg namespace. Even though the document is technically an XHTML document, the SVG code is considered valid because of the use of namespaces.
翻译:
在这个例子里,相对于最外围文档,SVG元素通过设置它自己的命名空间被分辨了出来。SVG所有的子元素以及子元素的所有属性都被认为在命名空间http://www.w3.org/2000/svg里面。即便这个文档技术性的被认为是XHTML,但是由于命名空间的使用,SVG的代码也是有效的。
The interesting problem with a document such as this is what happens when a method is called on the document to interact with nodes in the document. When a new element is created, which namespace does it belong to? When querying for a specifi c tag name, what namespaces should be included in the results? DOM Level 2 Core answers these questions by providing namespace-specifi c versions of most DOM Level 1 methods.
翻译:
有趣的问题是,在这样的一个文档中,当一个和文档中节点交互的方法被调用的时候会发生什么。当一个新的元素被创建,它又属于哪一个命名空间。当查询指定的标签的时候,什么命名空间应当被包含在结果里。通过提供和DOMLevel 1Core 类似的带命名空间的方法 , DOM Level 2Core回答了这些问题。
 
DOM Level 2
localName namespaceURI prefix
 
DOM Level 3
isDefaultNamespace(namespaceURI)
lookupNamespaceURI(prefi x)
lookupPrefix(namespaceURI)
 
Changes to Document
createElementNS(namespaceURI, tagName)
createAttributeNS(namespaceURI, attributeName)
getElementsByTagNameNS(namespaceURI, tagName)
 
想学习SVG,想到之前拜读的这本经典书籍里有提到,就先看看,毕竟对这本说已经产生了依赖感了!!!