org.w3c.dom.Attr说明

The Attr interface represents an attribute in an Element object. Typically the allowable values for the attribute are defined in a schema associated with the document.

Attr接口

Attr objects inherit the Node interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, the Node attributes parentNode, previousSibling, and nextSibling have a null value for Attr objects. The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with; this should make it more efficient to implement such features as default attributes associated with all elements of a given type. Furthermore, Attr nodes may not be immediate children of a DocumentFragment. However, they can be associated with Element nodes contained within a DocumentFragment. In short, users and implementors of the DOM need to be aware that Attr nodes have some things in common with other objects inheriting the Node interface, but they also are quite distinct.

The attribute’s effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute’s effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute’s effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that the Node.nodeValue attribute on the Attr instance can also be used to retrieve the string version of the attribute’s value(s).

If the attribute was not explicitly given a value in the instance document but has a default value provided by the schema associated with the document, an attribute node will be created with specified set to false. Removing attribute nodes for which a default value is defined in the schema generates a new attribute node with the default value and specified set to false. If validation occurred while invoking Document.normalizeDocument(), attribute nodes with specified equals to false are recomputed according to the default attribute values provided by the schema. If no default value is associate with this attribute in the schema, the attribute node is discarded.

In XML, where the value of an attribute can contain entity references, the child nodes of the Attr node may be either Text or EntityReference nodes (when these are in use; see the description of EntityReference for discussion).

The DOM Core represents all attribute values as simple strings, even if the DTD or schema associated with the document declares them of some specific type such as tokenized.

The way attribute value normalization is performed by the DOM implementation depends on how much the implementation knows about the schema in use. Typically, the value and nodeValue attributes of an Attr node initially returns the normalized value given by the parser. It is also the case after Document.normalizeDocument() is called (assuming the right options have been set). But this may not be the case after mutation, independently of whether the mutation is performed by setting the string value directly or by changing the Attr child nodes. In particular, this is true when character references are involved, given that they are not represented in the DOM and they impact attribute value normalization. On the other hand, if the implementation knows about the schema in use when the attribute value is changed, and it is of a different type than CDATA, it may normalize it again at that time. This is especially true of specialized DOM implementations, such as SVG DOM implementations, which store attribute values in an internal form different from a string.

The following table gives some examples of the relations between the attribute value in the original document (parsed attribute), the value as exposed in the DOM, and the serialization of the value:

Examples

Parsed attribute value

Initial Attr.value

Serialized attribute value

Character reference “x2=5”

“x\u00b2=5”

“x2=5”

Built-in character entity “y<6”

“y<6”

“y<6”

Literal newline between “x=5
y=6”

“x=5 y=6”

“x=5
y=6”

Normalized newline between “x=5

y=6”

“x=5 y=6”

“x=5 y=6”

Entity e with literal newline

时间: 2024-10-11 10:38:15

org.w3c.dom.Attr说明的相关文章

org.w3c.dom(java dom)解析XML文档

位于org.w3c.dom操作XML会比较简单,就是将XML看做是一颗树,DOM就是对这颗树的一个数据结构的描述,但对大型XML文件效果可能会不理想 首先来了解点Java DOM 的 API:1.解析器工厂类:DocumentBuilderFactory 创建的方法:DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 2.解析器:DocumentBuilder 创建方法:通过解析器工厂类来获得 DocumentBu

org.w3c.dom.ls.LSException: java.lang.NullPointerException

操作环境: OS:WIN 10.0.14393 x64 家庭版 JDK:JavaSE 1.5.0_20 i586 Tomcat:6.0.48 win32 ----------------------------------------------------------------- 操作过程: 执行startup.bat,启动Tomcat. ----------------------------------------------------------------- 异常信息: org.w

使用org.w3c.dom.Element的setTextContent()、getTextContent()方法时出现编译错误

今天在更新项目后进行编译时,出现如下错误一堆: Google之,在stackoverflow上看到如下的解决方法: I came here with the same problem. Even worse: I had two projects side by side, both targetting the same JRE (1.6), and one was able to resolve Node.getTextContent() while the other wasn't. I

org.w3c.dom.Element 缺少 setTextContent 步骤

org.w3c.dom.Element 缺少 setTextContent 方法 今天将项目环境由jdk5改为jdk6,eclipse重新编译工程后,却突然出现org.w3c.dom.Element没有setTextContent方法 的编译错. 放狗搜后,发现主要是 xercesImpl.jar 和 xml-apis.jar的Element版本太老造成的,setTextContent是DOM3中的方法. 但在pom文件中,未发现有直接引用这两个jar包的地方.好在eclipse maven插件

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

今天用maven编写Selenium测试程序时,调用 HtmlUnitDriver driver = new HtmlUnitDriver(true); 反法时报错如下: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal          at java.lang.ClassLoader.defineClass1(Native Method)          at java.lang.ClassLoader.defineC

W3C DOM 事件模型(简述)

1.事件模型 由于事件捕获与冒泡模型都有其长处和解释,DOM标准支持捕获型与冒泡型,能够说是它们两者的结合体.它能够在一个DOM元素上绑定多个事件处理器,而且在处理函数内部,thiskeyword仍然指向被绑定的DOM元素,另外处理函数參数列表的第一个位置传递事件event对象.首先是捕获式传递事件,接着是冒泡式传递,所以,假设一个处理函数既注冊了捕获型事件的监听,又注冊冒泡型事件监听,那么在DOM事件模型中它就会被调用两次. [ oschina] 2.事件传播 A)冒泡模式(Bubble)IE

W3C DOM

“W3C 文档对象模型 (DOM) 是中立于平台和语言的接口,它允许程序和脚本动态地访问和更新文档的内容.结构和样式.” DOM可以以一种独立于平台和语言的方式访问和修改一个文档的内容和结构. DOM实际上是以面向对象方式描述的文档模型.DOM定义了表示和修改文档所需的对象.这些对象的行为和属性以及这些对象之间的关系. 最初人们把它认为是一种让JavaScript在浏览器间可移植的方法,不过DOM的应用已经远远超出这个范围.Dom技术使得用户页面可以动态地变化,如可以动态地显示或隐藏一个元素,改

org.w3c.dom.Document 与org.dom4j.Document互转

public static Document parse(org.w3c.dom.Document doc) throws Exception { if (doc == null) { return (null); } org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader(); return (xmlReader.read(doc)); } public static org.w3c.dom.Document parse(Do

org.w3c.dom.Node.getTextContent()方法编译错误-已解决

org.w3c.dom.Node.getTextContent()方法编译错误. 在项目的Java Build Path | Order and Export选项卡中,将JRE System Library选中,并Top置顶.然后再进行编译即可. 参考: https://blog.csdn.net/maoxiao1229/article/details/51694553 原文地址:https://www.cnblogs.com/wrong/p/10441783.html