XML DOM - Element όν
- Προηγούμενη σελίδα DOM DOMParser
- Επόμενη σελίδα DOM Event
The Element object represents an element in the XML document. Elements can contain attributes, other elements, or text. If an element contains text, then this text is represented in the text node.
Element object
The Element object represents an element in the XML document. Elements can contain attributes, other elements, or text. If an element contains text, then this text is represented in the text node.
Important matters:Important note: Text is always stored in text nodes. A common error in the DOM processing process is to navigate to an element node and assume that this node contains text. However, even the simplest element node has a text node below it. For example, in <year>2005</year>, there is an element node (year), and below this node there is a text node containing the text (2005).
Since the element object is also a node, it can inherit the properties and methods of the Node object.
Attributes of the Element object
Attributes | Description | IE | F | O | W3C |
---|---|---|---|---|---|
attributes | Return the NamedNodeMap of the element's attributes | 5 | 1 | 9 | Ναι |
baseURI | Return the absolute base URI of the element | Όχι | 1 | Όχι | Ναι |
childNodes | Return the NodeList of the child nodes of the element | 5 | 1 | 9 | Ναι |
firstChild | Return the first child of the element | 5 | 1 | 9 | Ναι |
lastChild | Return the last child of the element | 5 | 1 | 9 | Ναι |
localName | Return the local part of the element name | Όχι | 1 | 9 | Ναι |
namespaceURI | Return the namespace URI of the element | Όχι | 1 | 9 | Ναι |
nextSibling | Return the node that follows the element immediately | 5 | 1 | 9 | Ναι |
nodeName | Return the name of the node, based on its type. | 5 | 1 | 9 | Ναι |
nodeType | Return the type of the node | 5 | 1 | 9 | Ναι |
ownerDocument | Return the root element of the element (document object) | 5 | 1 | 9 | Ναι |
parentNode | Return the parent node of the element | 5 | 1 | 9 | Ναι |
prefix | Set or return the namespace prefix of the element | Όχι | 1 | 9 | Ναι |
previousSibling | Return the node that precedes the element immediately | 5 | 1 | 9 | Ναι |
schemaTypeInfo | Return the type information associated with the element | Όχι | Ναι | ||
tagName | Return the name of the element | 5 | 1 | 9 | Ναι |
textContent | Set or return the text content of the element and its descendants | Όχι | 1 | Όχι | Ναι |
text | Return the text of the node and its descendants (IE-only) | 5 | Όχι | Όχι | Όχι |
xml | Return the XML of the node and its descendants (IE-only) | 5 | Όχι | Όχι | Όχι |
Methods of the Element object
Method | Description | IE | F | O | W3C |
---|---|---|---|---|---|
appendChild() | Add a new child node to the end of the node's child node list. | 5 | 1 | 9 | Ναι |
cloneNode() | Clone a node. | 5 | 1 | 9 | Ναι |
compareDocumentPosition() | Compare the document positions of two nodes. | Όχι | 1 | Όχι | Ναι |
dispatchEvent() | Assign a composite event to the node. | Όχι | 1 | 9 | Ναι |
getAttribute() | 返回属性的值。 | 5 | 1 | 9 | Ναι |
getAttributeNS() | 返回属性的值。 | Όχι | 1 | 9 | Ναι |
getAttributeNode() | 以 Attribute 对象返回属性节点。 | 5 | 1 | 9 | Ναι |
getAttributeNodeNS() | 以 Attribute 对象返回属性节点。 | Όχι | 9 | Ναι | |
getElementsByTagName() | 找到具有指定标签名的子孙元素。 | 5 | 1 | 9 | Ναι |
getElementsByTagNameNS() | 找到具有指定标签名和命名空间的元素。 | Όχι | 1 | 9 | Ναι |
getFeature(feature,version) | 返回 DOM 对象,此对象可执行拥有指定特性和版本的专门的 API。 | Όχι | Ναι | ||
getUserData(key) | 返回关联节点上键的对象。此对象必须首先通过使用相同的键来调用 setUserData 来设置到此节点。 | Όχι | Ναι | ||
hasAttribute() | 返回元素是否拥有指定的属性。 | 5 | 1 | 9 | Ναι |
hasAttributeNS() | 返回元素是否拥有指定的属性。 | Όχι | 1 | 9 | Ναι |
hasAttributes() | 返回元素是否拥有属性。 | 5 | 1 | 9 | Ναι |
hasChildNodes() | 返回元素是否拥有子节点。 | 5 | 1 | 9 | Ναι |
insertBefore() | 在已有的子节点之前插入一个新的子节点。 | 5 | 1 | 9 | Ναι |
isDefaultNamespace(URI) | 返回指定的命名空间 URI 是否为默认。 | Όχι | Ναι | ||
isEqualNode() | 检查两节点是否相等。 | Όχι | Όχι | Όχι | Ναι |
isSameNode() | 检查两节点是否为同一节点。 | Όχι | 1 | Όχι | Ναι |
isSupported(feature,version) | 返回指定的特性是否在此元素上得到支持。 | 9 | Ναι | ||
lookupNamespaceURI() | 返回匹配指定前缀的命名空间 URI。 | Όχι | 1 | Όχι | Ναι |
lookupPrefix() | 返回匹配指定的命名空间 URI 的前缀。 | Όχι | 1 | Όχι | Ναι |
normalize() | 5 | 1 | 9 | Ναι | |
removeAttribute() | 删除指定的属性。 | 5 | 1 | 9 | Ναι |
removeAttributeNS() | 删除指定的属性。 | Όχι | 1 | 9 | Ναι |
removeAttributeNode() | 删除指定的属性节点。 | 5 | 1 | 9 | Ναι |
removeChild() | 删除子节点。 | 5 | 1 | 9 | Ναι |
replaceChild() | 替换子节点。 | 5 | 1 | 9 | Ναι |
setUserData(key,data,handler) | 把对象关联到元素上的键。 | Όχι | Ναι | ||
setAttribute() | 添加新属性。 | 5 | 1 | 9 | Ναι |
setAttributeNS() | 添加新属性。 | 1 | 9 | Ναι | |
setAttributeNode() | Προσθήκη νέου κόμβου χαρακτηριστικού. | 5 | 1 | 9 | Ναι |
setAttributeNodeNS(attrnode) | Προσθήκη νέου κόμβου χαρακτηριστικού. | 9 | Ναι | ||
setIdAttribute(name,isId) | Αν το χαρακτηριστικό του αντικειμένου Attribute είναι isId και είναι αληθές, τότε αυτή η μέθοδος θα δηλώσει το καθορισμένο χαρακτηριστικό ως ένα χαρακτηριστικό χρήστη καθορισμένου ID (user-determined ID attribute). | Όχι | Ναι | ||
setIdAttributeNS(uri,name,isId) | Αν το χαρακτηριστικό του αντικειμένου Attribute είναι isId και είναι αληθές, τότε αυτή η μέθοδος θα δηλώσει το καθορισμένο χαρακτηριστικό ως ένα χαρακτηριστικό χρήστη καθορισμένου ID (user-determined ID attribute) (με ονομαστικό χώρο). | Όχι | Ναι | ||
setIdAttributeNode(idAttr,isId) | Αν το χαρακτηριστικό του αντικειμένου Attribute είναι isId και είναι αληθές, τότε αυτή η μέθοδος θα δηλώσει το καθορισμένο χαρακτηριστικό ως ένα χαρακτηριστικό χρήστη καθορισμένου ID (user-determined ID attribute). | Όχι | Ναι |
- Προηγούμενη σελίδα DOM DOMParser
- Επόμενη σελίδα DOM Event