w3pop.com :: 网络学院 :: XML DOM :: DOM Element
The Element object represents an element in an XML document. Elements may contain attributes, other elements, or text. If an element contains text, the text is represented in a text-node.
Element 对象表示一个XML文档中的某个元素。元素可包含属性、别的属性或文本。假如某个元素含有文本,则此文本由一个文本节点来代表。
IMPORTANT! Text is always stored in text nodes. A common error in DOM processing is to navigate to an element node and expect it to contain the text. However, even the simplest element node has a text node under it. For example, in <year>2005</year>, there is an element node (year), and a text node under it, which contains the text (2005).
重要提示:文本永远被存储于文本节点中。在DOM处理过程中的一个常见的错误是,导航到某个元素节点,并预期此节点含有 文本。然后,即使最简单的元素节点之下也拥有文本节点。举例,在<year>2005</year>中,其中存在一个元素节点 (year),同时此节点之下存在一个文本节点,其中含有文本(2005)。
Because the Element object is also a Node, it inherits the Node object's properties and methods.
因为元素对象也是一种节点,因此它可继承节点对象的属性和方法。
IE: Internet Explorer, F: Firefox[火狐], O: Opera, W3C: World Wide Web Consortium (Internet Standard) | 万维网联盟(国际标准)
| Property 属性 |
Description 描述 |
IE | F | O | W3C |
|---|---|---|---|---|---|
| attributes | Returns a NamedNodeMap of attributes for the element 返回元素属性的NamedNodeMap[指定节点映射] |
5 | 1 | 9 | Yes |
| baseURI | Returns the absolute base URI of the element 返回元素的绝对基准URI |
No | 1 | No | Yes |
| childNodes | Returns a NodeList of child nodes for the element 返回元素的子节点列表 |
5 | 1 | 9 | Yes |
| firstChild | Returns the first child of the element 返回元素的第一个子节点 |
5 | 1 | 9 | Yes |
| lastChild | Returns the last child of the element 返回元素的最后一个子节点 |
5 | 1 | 9 | Yes |
| localName | Returns the local part of the name of the element 返回元素的本地名称 |
No | 1 | 9 | Yes |
| namespaceURI | Returns the namespace URI of the element 返回元素的命名空间URI |
No | 1 | 9 | Yes |
| nextSibling | Returns the node immediately following the element 直接返回下一个元素节点 |
5 | 1 | 9 | Yes |
| nodeName | Returns the name of the node, depending on its type 返回于指定类型相对应的节点名称 |
5 | 1 | 9 | Yes |
| nodeType | Returns the type of the node 返回节点类型 |
5 | 1 | 9 | Yes |
| ownerDocument | Returns the root element (document object) for an element 返回一个元素的根元素(文档对象) |
5 | 1 | 9 | Yes |
| parentNode | Returns the parent node of the element 返回元素的父类节点 |
5 | 1 | 9 | Yes |
| prefix | Sets or returns the namespace prefix of the element 设置或返回元素的命名空间前缀 |
No | 1 | 9 | Yes |
| previousSibling | Returns the node immediately before the element 直接返回上一个元素节点 |
5 | 1 | 9 | Yes |
| schemaTypeInfo | Returns the type information associated with the element 返回与元素相关的类型信息 |
No | Yes | ||
| tagName | Returns the name of the element 返回元素名称 |
5 | 1 | 9 | Yes |
| textContent | Sets or returns the text content of the element and its descendants 设置或返回元素及其子元素的文本内容 |
No | 1 | No | Yes |
| text | Returns the text of the node and its descendants. IE-only property 设置或返回元素及其子元素的文本。仅IE支持该属性 |
5 | No | No | No |
| xml | Returns the XML of the node and its descendants. IE-only property 设置或返回元素及其子元素的XML。仅IE支持该属性 |
5 | No | No | No |
| Method 方法 |
Description 描述 |
IE | F | O | W3C |
|---|---|---|---|---|---|
| appendChild() | Adds a new child node to the end of the list of children of the node 在指定节点的子节点列表末尾添加一个新的子节点 |
5 | 1 | 9 | Yes |
| cloneNode() | Clones a node 克隆某个节点 |
5 | 1 | 9 | Yes |
| compareDocumentPosition() | Compares the document position of two nodes 比较两个节点的文档位置 |
No | 1 | No | Yes |
| getAttribute() | Returns the value of an attribute 返回一个属性值 |
5 | 1 | 9 | Yes |
| getAttributeNS() | Returns the value of an attribute (with a namespace) 通过指定的命名空间返回节点值 |
No | 1 | 9 | Yes |
| getAttributeNode() | Returns an attribute node as an Attribute object 以属性对象的形式返回一个属性节点 |
5 | 1 | 9 | Yes |
| getAttributeNodeNS() | Returns an attribute node (with a namespace) as an Attribute object 通过指定的命名空间并以属性对象的形式返回一个属性节点 |
No | 9 | Yes | |
| getElementsByTagName() | Returns a NodeList of matching element nodes, and their children 返回一个与指定元素节点及其子节点相匹配的节点列表 |
5 | 1 | 9 | Yes |
| getElementsByTagNameNS() | Returns a NodeList of matching element nodes (with a namespace), and their children 通过指定的命名空间返回一个与指定元素节点及其子节点相匹配的节点列表 |
No | 1 | 9 | Yes |
| getFeature(feature,version) | Returns a DOM object which implements the specialized APIs of the specified feature and version 返回一个用于执行指定特征和版本的APIs的DOM对象 |
No | Yes | ||
| getUserData(key) | Returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key 可返回关联节点上某个键的对象。此对象必须首先通过使用相同的键来调用setUserData来设置到此节点。 |
No | Yes | ||
| hasAttribute() | Returns whether an element has any attributes matching a specified name 返回一个元素是否拥有于指定名称相匹配的所有属性 |
5 | 1 | 9 | Yes |
| hasAttributeNS() | Returns whether an element has any attributes matching a specified name and namespace 返回一个元素是否拥有于指定名称与指定命名空间相匹配的所有属性 |
No | 1 | 9 | Yes |
| hasAttributes() | Returns whether the element has any attributes 返回元素是否包含属性 |
5 | 1 | 9 | Yes |
| hasChildNodes() | Returns whether the element has any child nodes 返回元素是否包含子节点 |
5 | 1 | 9 | Yes |
| insertBefore() | Inserts a new child node before an existing child node 在现有的子节点之前插入一个全新的子节点 |
5 | 1 | 9 | Yes |
| isDefaultNamespace(URI) | Returns whether the specified namespaceURI is the default 返回当前指定的namespaceURI[命名空间URI]是否是默认的 |
No | Yes | ||
| isEqualNode() | Checks if two nodes are equal 检验两个节点是否相等 |
No | No | No | Yes |
| isSameNode() | Checks if two nodes are the same node 检验两个节点是否相同 |
No | 1 | No | Yes |
| isSupported(feature,version) | Returns whether a specified feature is supported on the element 返回该指定的特征是否被当前元素支持 |
9 | Yes | ||
| lookupNamespaceURI() | Returns the namespace URI matching a specified prefix 返回与指定前缀相匹配的命名空间URI |
No | 1 | No | Yes |
| lookupPrefix() | Returns the prefix matching a specified namespace URI 返回与指定命名空间URI相匹配的前缀 |
No | 1 | No | Yes |
| normalize() | Puts all text nodes underneath this element (including attributes) into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes 其作用是规范化节点。它将一个节点(包括属性)下的所有文本节点按照规范化结构分隔文本节点(如:元素、注释、处理结构、CDATA、片断区域以及实体参数)的标准格式进行处理。这样操作后,节点中既不会出现相邻节点也不会出现空节点。 |
5 | 1 | 9 | Yes |
| removeAttribute() | Removes a specified attribute 删除一个指定的属性 |
5 | 1 | 9 | Yes |
| removeAttributeNS() | Removes a specified attribute (with a namespace) 通过一个指定的命名空间删除一个指定的属性 |
No | 1 | 9 | Yes |
| removeAttributeNode() | Removes a specified attribute node 删除一个指定的属性节点 |
5 | 1 | 9 | Yes |
| removeChild() | Removes a child node 删除一个子节点 |
5 | 1 | 9 | Yes |
| replaceChild() | Replaces a child node 替代一个子节点 |
5 | 1 | 9 | Yes |
| setUserData(key,data,handler) | Associates an object to a key on the element 将指定的对象与元素的键结合起来 |
No | Yes | ||
| setAttribute() | Adds a new attribute 添加一个全新的属性 |
5 | 1 | 9 | Yes |
| setAttributeNS() | Adds a new attribute (with a namespace) 通过一个指定的命名空间添加一个全新的属性 |
1 | 9 | Yes | |
| setAttributeNode() | Adds a new attribute node 添加一个全新的属性节点 |
5 | 1 | 9 | Yes |
| setAttributeNodeNS(attrnode) | Adds a new attribute node (with a namespace) 通过一个指定的命名空间添加一个全新的属性节点 |
9 | Yes | ||
| setIdAttribute(name,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute to be a user-determined ID attribute 如果属性对象中的isld属性为true,那么该方法将声明该指定的属性为用户自定义的ID属性 |
No | Yes | ||
| setIdAttributeNS(uri,name,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute (with a namespace) to be a user-determined ID attribute 如果属性对象中的isld属性为true,那么该方法将声明该指定的属性(包含命名空间)为用户自定义的ID属性 |
No | Yes | ||
| setIdAttributeNode(idAttr,isId) | If the isId property of the Attribute object is true, this method declares the specified attribute to be a user-determined ID attribute 如果属性对象中的isld属性为true,那么该方法将声明该指定的属性为用户自定义的ID属性 |
No | Yes |
评论 (0)
All