全栈JavaScript之路( 二十三 )DOM2、DOM3, 涉及XML命名空间的扩展(一)
2014-07-10 11:11
441 查看
<!DOCTYPE html> <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"> <head> <title>Example XHTML page</title> </head> <body> <s:svg xmlns:s="http://www.w3.org/2000/svg" version="1.1" style="width:100%; height:100%; viewBox:0 10 10 10"> <s:rect x="0" y="0" width="100" height="100" style="fill:red"/> </s:svg> </body> </xhtml:html>
以上例子展示,通过 xmlns 来指定命名空间,通过 xmlns:prefix 来指定 前缀,一但指定的前缀,就得在当前元素,以及子元素使用。
有时候为了避免不同语言间的冲突,也需要使用命名空间来限定特性,如下面的例子所示。
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"> <xhtml:head> <xhtml:title>Example XHTML page</xhtml:title> </xhtml:head> <xhtml:body xhtml:class="home"> Hello world! </xhtml:body> </xhtml:html>
(一)Node类型的变化:
在DOM2中 Node类型包含了下表特定于命名空间的特性
localName
prefix
namespaceURL
在DOM3中,更进一步增加了下列属性和方法
isDefaultNamaspace(namespaceURL)
lookupNamespaceURL(prefix)
lookupPrefix(namespaceURL)
(二)Document 类型的变化
createElementNS(namespaceURL,tagName)
createAttributeNS(namespaceURL,tagName)
getElementByTagName(namespaceURL,tagName)
只有文档中存在两个或多个命名空间的时候,这些跟命名空间相关的方法才是必须的。
(三)Element 类型的变化
DOM core 中 ,涉及命名空间的变化 ,主要是操作特性的方法。
getAttributeNS(namespaceURL,localName)
getAttributeNodeNS(namespaceURL,localName)
getElementByTagName(namespaceURL,tagName)
hasAttribute(namespaceURL,tagName) //dom 也同时增加了 hasAttribute()
removeAttributeNS(namespaceURL,localName)
setAttributeNS(namespaceURL,localName,value)
setAttributeNodeNS(namespaceURL,attNode)
除了第一个参数之外,这些方法与DOM1 级中相关方法的作用相同;第一个参数始终都是一个命名空间URI。
(四) NamedNodeMap 类型的变化
getNamedItemNS(namespaceURL,localName)
setNamedItemNS(node)
removeNamedItemNS(namespaceURL,localName)
由于一般都是通过元素访问特性,所以这些方法很少使用。
相关文章推荐
- 全栈JavaScript之路( 二十四 )DOM2、DOM3, 不涉及XML命名空间的扩展
- JavaScript高级程序设计之DOM2和DOM3之DOM 变化之针对XML命名空间的变化第12.1.1讲
- 用dom解读xml的时候,如果碰到有命名空间的时候(就是节点名字有:的时候)需要把xml文件中的那个命名空间地址和名字拿出来加到XmlNamespaceManager 里面去
- ASP.NET AJAX 说明文档->客户端引用->全局命名空间->JavaScript 基础类型扩展->Array 类型扩展->contains 函数
- 关于XML命名空间
- 关于xml的命名空间(转自国外一blog)
- xml命名空间和实现机制
- XML技术讲座之六 XML中的命名空间
- .net操作带命名空间的xml(仅列一个获取节点值的例子其他以此类推)
- ASP.NET AJAX 说明文档->客户端引用->全局命名空间->JavaScript 基础类型扩展->Array 类型扩展->clone 函数
- XML指南——XML 命名空间
- XML 命名空间
- 比较清楚的介绍 外壳命名空间扩展 (转载)
- XML与XML 命名空间(Namespaces)
- XML命名空间以及它们如何影响XPath和XSLT(Extreme XML)
- XML 命名空间
- XML 命名空间提供了一种避免元素命名冲突的方法。
- XML指南——XML 命名空间
- XML之命名空间[转载]
- xml 总结(一)数据岛,命名空间