XML DOM - Node 对象
- Föregående sida DOM NamedNodeMap
- Nästa sida DOM NodeList
节点对象代表文档树中的一个节点。
Node 对象
Node 对象是整个 DOM 的主要数据类型。
节点对象代表文档树中的一个单独的节点。
节点可以是元素节点、属性节点、文本节点,或者也可以是“节点类型”那一节中所介绍的任何一种节点。
请注意,虽然所有的对象均能继承用于处理父节点和子节点的属性和方法,但是并不是所有的对象都拥有父节点或子节点。例如,文本节点不能拥有子节点,所以向类似的节点添加子节点就会导致 DOM 错误。
IE: Internet Explorer: F: Firefox: O: Opera: W3C: World Wide Web Consortium (Internet standards)
Properties of Node object
Property | Description | IE | F | O | W3C |
---|---|---|---|---|---|
baseURI | Return the absolute base URI of the node. | Nej | 1 | Nej | Ja |
childNodes | Return the node list from the node to its child nodes. | 5 | 1 | 9 | Ja |
firstChild | Return the first child node of the node. | 5 | 1 | 9 | Ja |
lastChild | Return the last child node of the node. | 5 | 1 | 9 | Ja |
localName | Return the local name of the node. | Nej | 1 | 9 | Ja |
namespaceURI | Return the namespace URI of the node. | Nej | 1 | 9 | Ja |
nextSibling | Return the sibling node immediately following the node. | 5 | 1 | 9 | Ja |
nodeName | Return the name of the node, depending on its type. | 5 | 1 | 9 | Ja |
nodeType | Return the type of the node. | 5 | 1 | 9 | Ja |
nodeValue | Set or return the value of the node, depending on its type. | 5 | 1 | 9 | Ja |
ownerDocument | Return the root element of the node (document object). | 5 | 1 | 9 | Ja |
parentNode | Return the parent node of the node. | 5 | 1 | 9 | Ja |
prefix | Set or return the namespace prefix of the node. | Nej | 1 | 9 | Ja |
previousSibling | Return the sibling node immediately preceding the node. | 5 | 1 | 9 | Ja |
textContent | Set or return the text content of the node and its descendants. | Nej | 1 | Nej | Ja |
text | Return the text of the node and its descendants (IE-specific property). | 5 | Nej | Nej | Nej |
xml | Return the XML of the node and its descendants (IE-specific property). | 5 | Nej | Nej | Nej |
Methods of Node 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 | Ja |
cloneNode() | Copy a node. | 5 | 1 | 9 | Ja |
compareDocumentPosition() | Compare the document positions of two nodes. | Nej | 1 | Nej | Ja |
getFeature(feature,version) | Return a DOM object that can execute a specialized API with the specified features and version. | Nej | Ja | ||
getUserData(key) | Return the object associated with a key on this node. This object must first be set to this node by calling setUserData with the same key. | Nej | Ja | ||
hasAttributes() | Determine if the current node has attributes. | Nej | 1 | 9 | Ja |
hasChildNodes() | Determine if the current node has child nodes. | 5 | 1 | 9 | Ja |
insertBefore() | Insert a new child node before the specified child node. | 5 | 1 | 9 | Ja |
isDefaultNamespace(URI) | Return if the specified namespace URI is the default. | Nej | Ja | ||
isEqualNode() | Kontrollera om två noder är lika. | Nej | Nej | Nej | Ja |
isSameNode() | Kontrollera om två noder är samma nod. | Nej | 1 | Nej | Ja |
isSupported() | Returnera om den aktuella noden stöder en viss egenskap. | 9 | Ja | ||
lookupNamespaceURI() | Returnera namnrymd URI:en som matchar det specifika prefixet. | Nej | 1 | Nej | Ja |
lookupPrefix() | Returnera prefixet som matchar den specifika namnrymd URI:en. | Nej | 1 | Nej | Ja |
normalize() | Kombinera närliggande Text-noder och ta bort tomma Text-noder. | 5 | 1 | 9 | Ja |
removeChild() | Ta bort (och returnera) den specifika undernoden för den aktuella noden. | 5 | 1 | 9 | Ja |
replaceChild() | Erstätt en undernod med en ny nod. | 5 | 1 | 9 | Ja |
selectNodes() | Använd en XPath-uttryck för att välja noder. | 6 | |||
selectSingleNode() | Sök och hitta en nod som matchar en XPath-fråga. | 6 | |||
transformNode() | Använd XSLT för att konvertera en nod till en sträng. | 6 | |||
transformNodeToObject() | Använd XSLT för att konvertera en nod till ett dokument. | 6 | |||
setUserData(key, data, handler) | Länka ett objekt till en nyckel på en noder. | Nej | Ja |
- Föregående sida DOM NamedNodeMap
- Nästa sida DOM NodeList