Movatterモバイル変換


[0]ホーム

URL:


         


Interface Node

All Known Subinterfaces:
Attr,CDATASection,CharacterData,Comment,Document,DocumentFragment,DocumentType,Element,Entity,EntityReference,Notation,ProcessingInstruction,Text

public interfaceNode

TheNode interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing theNode interface expose methods for dealing with children, not all objects implementing theNode interface may have children. For example,Text nodes may not have children, and adding children to such nodes results in aDOMException being raised.

The attributesnodeName,nodeValue andattributes are included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specificnodeType (e.g.,nodeValue for anElement orattributes for aComment ), this returnsnull. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

The values ofnodeName,nodeValue, andattributes vary according to the node type as follows:

InterfacenodeNamenodeValueattributes
Attrname of attributevalue of attributenull
CDATASection"#cdata-section" content of the CDATA Sectionnull
Comment"#comment"content of the commentnull
Document"#document"nullnull
DocumentFragment"#document-fragment"nullnull
DocumentTypedocument type name nullnull
Elementtag namenullNamedNodeMap
Entityentity namenullnull
EntityReferencename of entity referencednullnull
Notationnotation namenull null
ProcessingInstructiontargetentire content excluding the targetnull
Text"#text"content of the text nodenull

See also theDocument Object Model (DOM) Level 2 Core Specification.


ATTRIBUTE_NODE
          The node is anAttr.
CDATA_SECTION_NODE
          The node is aCDATASection.
COMMENT_NODE
          The node is aComment.
DOCUMENT_FRAGMENT_NODE
          The node is aDocumentFragment.
DOCUMENT_NODE
          The node is aDocument.
DOCUMENT_TYPE_NODE
          The node is aDocumentType.
ELEMENT_NODE
          The node is anElement.
ENTITY_NODE
          The node is anEntity.
ENTITY_REFERENCE_NODE
          The node is anEntityReference.
NOTATION_NODE
          The node is aNotation.
PROCESSING_INSTRUCTION_NODE
          The node is aProcessingInstruction.
TEXT_NODE
          The node is aText node.
 
appendChild(Node newChild)
          Adds the nodenewChild to the end of the list of children of this node.
cloneNode(boolean deep)
          Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
getAttributes()
          ANamedNodeMap containing the attributes of this node (if it is anElement) ornull otherwise.
getChildNodes()
          ANodeList that contains all children of this node.
getFirstChild()
          The first child of this node.
getLastChild()
          The last child of this node.
getLocalName()
          Returns the local part of the qualified name of this node.
getNamespaceURI()
          The namespace URI of this node, ornull if it is unspecified.
getNextSibling()
          The node immediately following this node.
getNodeName()
          The name of this node, depending on its type; see the table above.
getNodeType()
          A code representing the type of the underlying object, as defined above.
getNodeValue()
          The value of this node, depending on its type; see the table above.
getOwnerDocument()
          TheDocument object associated with this node.
getParentNode()
          The parent of this node.
getPrefix()
          The namespace prefix of this node, ornull if it is unspecified.
getPreviousSibling()
          The node immediately preceding this node.
hasAttributes()
          Returns whether this node (if it is an element) has any attributes.
hasChildNodes()
          Returns whether this node has any children.
insertBefore(Node newChild,Node refChild)
          Inserts the nodenewChild before the existing child noderefChild.
isSupported(java.lang.String feature, java.lang.String version)
          Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
normalize()
          Puts allText nodes in the full depth of the sub-tree underneath thisNode, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separatesText nodes, i.e., there are neither adjacentText nodes nor emptyText nodes.
removeChild(Node oldChild)
          Removes the child node indicated byoldChild from the list of children, and returns it.
replaceChild(Node newChild,Node oldChild)
          Replaces the child nodeoldChild withnewChild in the list of children, and returns theoldChild node.
setNodeValue(java.lang.String nodeValue)
          The value of this node, depending on its type; see the table above.
setPrefix(java.lang.String prefix)
          The namespace prefix of this node, ornull if it is unspecified.
 

ELEMENT_NODE

public static final shortELEMENT_NODE
The node is anElement.

ATTRIBUTE_NODE

public static final shortATTRIBUTE_NODE
The node is anAttr.

TEXT_NODE

public static final shortTEXT_NODE
The node is aText node.

CDATA_SECTION_NODE

public static final shortCDATA_SECTION_NODE
The node is aCDATASection.

ENTITY_REFERENCE_NODE

public static final shortENTITY_REFERENCE_NODE
The node is anEntityReference.

ENTITY_NODE

public static final shortENTITY_NODE
The node is anEntity.

PROCESSING_INSTRUCTION_NODE

public static final shortPROCESSING_INSTRUCTION_NODE
The node is aProcessingInstruction.

COMMENT_NODE

public static final shortCOMMENT_NODE
The node is aComment.

DOCUMENT_NODE

public static final shortDOCUMENT_NODE
The node is aDocument.

DOCUMENT_TYPE_NODE

public static final shortDOCUMENT_TYPE_NODE
The node is aDocumentType.

DOCUMENT_FRAGMENT_NODE

public static final shortDOCUMENT_FRAGMENT_NODE
The node is aDocumentFragment.

NOTATION_NODE

public static final shortNOTATION_NODE
The node is aNotation.

getNodeName

public java.lang.StringgetNodeName()
The name of this node, depending on its type; see the table above.

getNodeValue

public java.lang.StringgetNodeValue()                              throwsDOMException
The value of this node, depending on its type; see the table above. When it is defined to benull, setting it has no effect.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
DOMException - DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMString variable on the implementation platform.

setNodeValue

public voidsetNodeValue(java.lang.String nodeValue)                  throwsDOMException
The value of this node, depending on its type; see the table above. When it is defined to benull, setting it has no effect.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
DOMException - DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMString variable on the implementation platform.

getNodeType

public shortgetNodeType()
A code representing the type of the underlying object, as defined above.

getParentNode

publicNodegetParentNode()
The parent of this node. All nodes, exceptAttr,Document,DocumentFragment,Entity, andNotation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this isnull.

getChildNodes

publicNodeListgetChildNodes()
ANodeList that contains all children of this node. If there are no children, this is aNodeList containing no nodes.

getFirstChild

publicNodegetFirstChild()
The first child of this node. If there is no such node, this returnsnull.

getLastChild

publicNodegetLastChild()
The last child of this node. If there is no such node, this returnsnull.

getPreviousSibling

publicNodegetPreviousSibling()
The node immediately preceding this node. If there is no such node, this returnsnull.

getNextSibling

publicNodegetNextSibling()
The node immediately following this node. If there is no such node, this returnsnull.

getAttributes

publicNamedNodeMapgetAttributes()
ANamedNodeMap containing the attributes of this node (if it is anElement) ornull otherwise.

getOwnerDocument

publicDocumentgetOwnerDocument()
TheDocument object associated with this node. This is also theDocument object used to create new nodes. When this node is aDocument or aDocumentType which is not used with anyDocument yet, this isnull.

insertBefore

publicNodeinsertBefore(Node newChild,Node refChild)                  throwsDOMException
Inserts the nodenewChild before the existing child noderefChild. IfrefChild isnull, insertnewChild at the end of the list of children.
IfnewChild is aDocumentFragment object, all of its children are inserted, in the same order, beforerefChild. If thenewChild is already in the tree, it is first removed.
Parameters:
newChild - The node to insert.
refChild - The reference node, i.e., the node before which the new node must be inserted.
Returns:
The node being inserted.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild node, or if the node to insert is one of this node's ancestors or this node itself.
WRONG_DOCUMENT_ERR: Raised ifnewChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the parent of the node being inserted is readonly.
NOT_FOUND_ERR: Raised ifrefChild is not a child of this node.

replaceChild

publicNodereplaceChild(Node newChild,Node oldChild)                  throwsDOMException
Replaces the child nodeoldChild withnewChild in the list of children, and returns theoldChild node.
IfnewChild is aDocumentFragment object,oldChild is replaced by all of theDocumentFragment children, which are inserted in the same order. If thenewChild is already in the tree, it is first removed.
Parameters:
newChild - The new node to put in the child list.
oldChild - The node being replaced in the list.
Returns:
The node replaced.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild node, or if the node to put in is one of this node's ancestors or this node itself.
WRONG_DOCUMENT_ERR: Raised ifnewChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of the new node is readonly.
NOT_FOUND_ERR: Raised ifoldChild is not a child of this node.

removeChild

publicNoderemoveChild(Node oldChild)                 throwsDOMException
Removes the child node indicated byoldChild from the list of children, and returns it.
Parameters:
oldChild - The node being removed.
Returns:
The node removed.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifoldChild is not a child of this node.

appendChild

publicNodeappendChild(Node newChild)                 throwsDOMException
Adds the nodenewChild to the end of the list of children of this node. If thenewChild is already in the tree, it is first removed.
Parameters:
newChild - The node to add.If it is aDocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
Returns:
The node added.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild node, or if the node to append is one of this node's ancestors or this node itself.
WRONG_DOCUMENT_ERR: Raised ifnewChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the previous parent of the node being inserted is readonly.

hasChildNodes

public booleanhasChildNodes()
Returns whether this node has any children.
Returns:
true if this node has any children,false otherwise.

cloneNode

publicNodecloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; (parentNode isnull.).
Cloning anElement copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a childText node. Cloning anAttribute directly, as opposed to be cloned as part of anElement cloning operation, returns a specified attribute (specified istrue). Cloning any other type of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy, but the children of anEntityReference clone are readonly . In addition, clones of unspecifiedAttr nodes are specified. And, cloningDocument,DocumentType,Entity, andNotation nodes is implementation dependent.
Parameters:
deep - Iftrue, recursively clone the subtree under the specified node; iffalse, clone only the node itself (and its attributes, if it is anElement).
Returns:
The duplicate node.

normalize

public voidnormalize()
Puts allText nodes in the full depth of the sub-tree underneath thisNode, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separatesText nodes, i.e., there are neither adjacentText nodes nor emptyText nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document containsCDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate betweenText nodes andCDATASection nodes.

isSupported

public booleanisSupported(java.lang.String feature,                           java.lang.String version)
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
Parameters:
feature - The name of the feature to test. This is the same name which can be passed to the methodhasFeature onDOMImplementation.
version - This is the version number of the feature to test. In Level 2, version 1, this is the string "2.0". If the version is not specified, supporting any version of the feature will cause the method to returntrue.
Returns:
Returnstrue if the specified feature is supported on this node,false otherwise.
Since:
DOM Level 2

getNamespaceURI

public java.lang.StringgetNamespaceURI()
The namespace URI of this node, ornull if it is unspecified.
This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
For nodes of any type other thanELEMENT_NODE andATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such ascreateElement from theDocument interface, this is alwaysnull.Per the Namespaces in XML Specification an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.
Since:
DOM Level 2

getPrefix

public java.lang.StringgetPrefix()
The namespace prefix of this node, ornull if it is unspecified.
Note that setting this attribute, when permitted, changes thenodeName attribute, which holds the qualified name, as well as thetagName andname attributes of theElement andAttr interfaces, when applicable.
Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since thenamespaceURI andlocalName do not change.
For nodes of any type other thanELEMENT_NODE andATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such ascreateElement from theDocument interface, this is alwaysnull.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified prefix contains an illegal character, per the XML 1.0 specification .
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NAMESPACE_ERR: Raised if the specifiedprefix is malformed per the Namespaces in XML specification, if thenamespaceURI of this node isnull, if the specified prefix is "xml" and thenamespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace", if this node is an attribute and the specified prefix is "xmlns" and thenamespaceURI of this node is different from " http://www.w3.org/2000/xmlns/", or if this node is an attribute and thequalifiedName of this node is "xmlns" .
Since:
DOM Level 2

setPrefix

public voidsetPrefix(java.lang.String prefix)               throwsDOMException
The namespace prefix of this node, ornull if it is unspecified.
Note that setting this attribute, when permitted, changes thenodeName attribute, which holds the qualified name, as well as thetagName andname attributes of theElement andAttr interfaces, when applicable.
Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since thenamespaceURI andlocalName do not change.
For nodes of any type other thanELEMENT_NODE andATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such ascreateElement from theDocument interface, this is alwaysnull.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified prefix contains an illegal character, per the XML 1.0 specification .
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NAMESPACE_ERR: Raised if the specifiedprefix is malformed per the Namespaces in XML specification, if thenamespaceURI of this node isnull, if the specified prefix is "xml" and thenamespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace", if this node is an attribute and the specified prefix is "xmlns" and thenamespaceURI of this node is different from " http://www.w3.org/2000/xmlns/", or if this node is an attribute and thequalifiedName of this node is "xmlns" .
Since:
DOM Level 2

getLocalName

public java.lang.StringgetLocalName()
Returns the local part of the qualified name of this node.
For nodes of any type other thanELEMENT_NODE andATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such ascreateElement from theDocument interface, this is alwaysnull.
Since:
DOM Level 2

hasAttributes

public booleanhasAttributes()
Returns whether this node (if it is an element) has any attributes.
Returns:
true if this node has any attributes,false otherwise.
Since:
DOM Level 2

         


[8]ページ先頭

©2009-2025 Movatter.jp