Most visited

Recently visited

Added in API level 1

NamedNodeMap

public interface NamedNodeMap

org.w3c.dom.NamedNodeMap


实现NamedNodeMap接口的对象用于表示可以按名称访问的节点集合。 请注意, NamedNodeMap不会从NodeList继承; NamedNodeMaps不以任何特定顺序维护。 包含在实现NamedNodeMap的对象中的对象也可以通过序号索引来访问,但这仅仅是为了便于列举NamedNodeMap的内容,并不意味着DOM指定了这些节点的顺序。

NamedNodeMap DOM中的对象是活的。

另请参阅 Document Object Model (DOM) Level 3 Core Specification

Summary

Public methods

abstract int getLength()

此地图中的节点数量。

abstract Node getNamedItem(String name)

检索由名称指定的节点。

abstract Node getNamedItemNS(String namespaceURI, String localName)

检索由本地名称和名称空间URI指定的节点。

abstract Node item(int index)

返回地图中的第 index个项目。

abstract Node removeNamedItem(String name)

删除由名称指定的节点。

abstract Node removeNamedItemNS(String namespaceURI, String localName)

删除由本地名称和名称空间URI指定的节点。

abstract Node setNamedItem(Node arg)

使用其属性 nodeName添加节点。

abstract Node setNamedItemNS(Node arg)

使用其 namespaceURIlocalName添加一个节点。

Public methods

getLength

Added in API level 1
int getLength ()

此地图中的节点数量。 有效子节点索引的范围是0length-1含)。

Returns
int

getNamedItem

Added in API level 1
Node getNamedItem (String name)

检索由名称指定的节点。

Parameters
name String: The nodeName of a node to retrieve.
Returns
Node A Node (of any type) with the specified nodeName, or null if it does not identify any node in this map.

getNamedItemNS

Added in API level 1
Node getNamedItemNS (String namespaceURI, 
                String localName)

检索由本地名称和名称空间URI指定的节点。
根据[ XML Namespaces ],如果应用程序希望没有命名空间,则必须将值作为namespaceURI参数使用。

Parameters
namespaceURI String: The namespace URI of the node to retrieve.
localName String: The local name of the node to retrieve.
Returns
Node A Node (of any type) with the specified local name and namespace URI, or null if they do not identify any node in this map.
Throws
DOMException NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).

item

Added in API level 1
Node item (int index)

返回地图中的第index个项目。 如果index大于或等于此映射中的节点数,则返回null

Parameters
index int: Index into this map.
Returns
Node The node at the indexth position in the map, or null if that is not a valid index.

removeNamedItem

Added in API level 1
Node removeNamedItem (String name)

删除由名称指定的节点。 当此映射包含附加到元素的属性时,如果已知的已删除属性具有默认值,则会立即显示一个属性,其中包含默认值以及相应的名称空间URI,本地名称和前缀(如果适用)。

Parameters
name String: The nodeName of the node to remove.
Returns
Node The node removed from this map if a node with such a name exists.
Throws
DOMException NOT_FOUND_ERR: Raised if there is no node named name in this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.

removeNamedItemNS

Added in API level 1
Node removeNamedItemNS (String namespaceURI, 
                String localName)

删除由本地名称和名称空间URI指定的节点。 如果此映射包含附加到元素的属性(如Node接口的属性属性所返回),则可以知道已删除的属性具有默认值。 如果是这样,一个属性立即出现,包含默认值以及相应的名称空间URI,本地名称和前缀(如果适用)。
根据[ XML Namespaces ],如果应用程序希望没有名称空间,则必须将值作为namespaceURI参数使用。

Parameters
namespaceURI String: The namespace URI of the node to remove.
localName String: The local name of the node to remove.
Returns
Node The node removed from this map if a node with such a local name and namespace URI exists.
Throws
DOMException NOT_FOUND_ERR: Raised if there is no node with the specified namespaceURI and localName in this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).

setNamedItem

Added in API level 1
Node setNamedItem (Node arg)

使用nodeName属性添加节点。 如果具有该名称的节点已经存在于该映射中,它将被替换为新映射。 自行更换节点不起作用。
由于nodeName属性用于派生节点必须存储的名称,因此某些类型的多个节点(具有“特殊”字符串值的节点)不能存储,因为名称会冲突。 这被认为比允许节点被别名更可取。

Parameters
arg Node: A node to store in this map. The node will later be accessible using the value of its nodeName attribute.
Returns
Node If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
Throws
DOMException WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object. The DOM user must explicitly clone Attr nodes to re-use them in other elements.
HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. Examples would include trying to insert something other than an Attr node into an Element's map of attributes, or a non-Entity node into the DocumentType's map of Entities.

setNamedItemNS

Added in API level 1
Node setNamedItemNS (Node arg)

使用namespaceURIlocalName添加一个节点。 如果具有该名称空间URI和该本地名称的节点已经存在于此映射中,它将被替换为新映射。 自行更换节点不起作用。
根据[ XML Namespaces ],如果应用程序希望没有名称空间,则必须将值作为namespaceURI参数使用。

Parameters
arg Node: A node to store in this map. The node will later be accessible using the value of its namespaceURI and localName attributes.
Returns
Node If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
Throws
DOMException WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object. The DOM user must explicitly clone Attr nodes to re-use them in other elements.
HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node doesn't belong in this NamedNodeMap. Examples would include trying to insert something other than an Attr node into an Element's map of attributes, or a non-Entity node into the DocumentType's map of Entities.
NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).

Hooray!