当前位置: 技术问答>java相关
请教:node.cloneNode(boolean deep)如何用
来源: 互联网 发布时间:2015-08-17
本文导语: cloneNode public Node cloneNode(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 is null.). Cloning an Element copies all attributes and their values...
cloneNode
public Node cloneNode(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 is null.).
Cloning an Element 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 child Text node. Cloning an Attribute directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute ( specified is true). 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 an EntityReference clone are readonly . In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and Notation nodes is implementation dependent.
Parameters:
deep - If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Returns:
The duplicate node.
这是jwsp的帮助,按理来说,应该写作:
node.cloneNode(false)
但是这样写编译不过:
Test.java:21: incompatible types
found : org.w3c.dom.Node
required: org.w3c.dom.Element
eCurNode = eTmp1.cloneNode(false);
^
到底应该怎么写啊:(
public Node cloneNode(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 is null.).
Cloning an Element 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 child Text node. Cloning an Attribute directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute ( specified is true). 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 an EntityReference clone are readonly . In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and Notation nodes is implementation dependent.
Parameters:
deep - If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Returns:
The duplicate node.
这是jwsp的帮助,按理来说,应该写作:
node.cloneNode(false)
但是这样写编译不过:
Test.java:21: incompatible types
found : org.w3c.dom.Node
required: org.w3c.dom.Element
eCurNode = eTmp1.cloneNode(false);
^
到底应该怎么写啊:(
|
eCurNode = ( Element )eTmp1.cloneNode(false);