Interface Branch
- All Known Implementing Classes:
AbstractBranch, AbstractDocument, AbstractElement, BaseElement, BeanElement, DefaultDocument, DefaultElement, DOMDocument, DOMElement, IndexedElement, NonLazyElement, UserDataElement
Branch
interface defines the common behaviour for Nodes which
can contain child nodes (content) such as XML elements and documents. This
interface allows both elements and documents to be treated in a polymorphic
manner when changing or navigating child nodes (content).- Version:
- $Revision: 1.32 $
-
Field Summary
Fields inherited from interface Node
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the givenComment
to this branch.void
Adds the givenElement
to this branch.void
Adds the givenNode
or throwsIllegalAddException
if the given node is not of a valid type.void
Adds the givenProcessingInstruction
to this branch.addElement
(String name) Adds a newElement
node with the given name to this branch and returns a reference to the new node.addElement
(String qualifiedName, String namespaceURI) Adds a newElement
node with the given qualified name and namespace URI to this branch and returns a reference to the new node.addElement
(QName qname) Adds a newElement
node with the givenQName
to this branch and returns a reference to the new node.void
appendContent
(Branch branch) Appends the content of the given branch to this branch instance.void
Clears the content for this branch, removing anyNode
instances this branch may contain.content()
elementByID
(String elementID) Returns the element of the given ID attribute value.int
Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.node
(int index) Returns theNode
at the specified index position.int
Returns the number ofNode
instances that this branch contains.Returns an iterator through the content nodes of this branchvoid
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.processingInstruction
(String target) DOCUMENT ME!Returns a list of all the processing instructions in this branch.processingInstructions
(String target) Returns a list of the processing instructions for the given target.boolean
Removes the givenComment
if the node is an immediate child of this branch.boolean
Removes the givenElement
if the node is an immediate child of this branch.boolean
Removes the givenNode
if the node is an immediate child of this branch.boolean
Removes the givenProcessingInstruction
if the node is an immediate child of this branch.boolean
removeProcessingInstruction
(String target) Removes the processing instruction for the given target if it existsvoid
setContent
(List<Node> content) Sets the contents of this branch as aList
ofNode
instances.void
setProcessingInstructions
(List<ProcessingInstruction> listOfPIs) Sets all the processing instructions for this branchMethods inherited from interface Node
accept, asXML, asXPathResult, clone, createXPath, detach, getDocument, getName, getNodeType, getNodeTypeName, getParent, getPath, getPath, getStringValue, getText, getUniquePath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf, write
-
Method Details
-
node
Returns theNode
at the specified index position.- Parameters:
index
- the index of the node to return.- Returns:
- the
Node
at the specified position. - Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >=nodeCount()
).
-
indexOf
Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.- Parameters:
node
- the content child node to find.- Returns:
- the index of the given node starting at 0 or -1 if the node is not a child node of this branch
-
nodeCount
int nodeCount()Returns the number ofNode
instances that this branch contains.- Returns:
- the number of nodes this branch contains
-
elementByID
Returns the element of the given ID attribute value. If this tree is capable of understanding which attribute value should be used for the ID then it should be used, otherwise this method should return null.- Parameters:
elementID
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
content
Returns the content nodes of this branch as a backedList
so that the content of this branch may be modified directly using theList
interface. TheList
is backed by theBranch
so that changes to the list are reflected in the branch and vice versa.- Returns:
- the nodes that this branch contains as a
List
-
nodeIterator
-
setContent
-
appendContent
Appends the content of the given branch to this branch instance. This method behaves like theCollection.addAll(java.util.Collection)
method.- Parameters:
branch
- is the branch whose content will be added to me.
-
clearContent
void clearContent()Clears the content for this branch, removing anyNode
instances this branch may contain. -
processingInstructions
List<ProcessingInstruction> processingInstructions()Returns a list of all the processing instructions in this branch. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Returns:
- a backed list of the processing instructions
-
processingInstructions
Returns a list of the processing instructions for the given target. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Parameters:
target
- DOCUMENT ME!- Returns:
- a backed list of the processing instructions
-
processingInstruction
DOCUMENT ME!- Parameters:
target
- DOCUMENT ME!- Returns:
- the processing instruction for the given target
-
setProcessingInstructions
Sets all the processing instructions for this branch- Parameters:
listOfPIs
- DOCUMENT ME!
-
addElement
-
addElement
-
addElement
Adds a newElement
node with the given qualified name and namespace URI to this branch and returns a reference to the new node.- Parameters:
qualifiedName
- is the fully qualified name of the ElementnamespaceURI
- is the URI of the namespace to use- Returns:
- the newly added
Element
node.
-
removeProcessingInstruction
Removes the processing instruction for the given target if it exists- Parameters:
target
- DOCUMENT ME!- Returns:
- true if a processing instruction was removed else false
-
add
Adds the givenNode
or throwsIllegalAddException
if the given node is not of a valid type. This is a polymorphic method which will call the typesafe method for the node type such as add(Element) or add(Comment).- Parameters:
node
- is the given node to add
-
add
Adds the givenComment
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.- Parameters:
comment
- is the comment to be added
-
add
Adds the givenElement
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.- Parameters:
element
- is the element to be added
-
add
Adds the givenProcessingInstruction
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.- Parameters:
pi
- is the processing instruction to be added
-
remove
Removes the givenNode
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead. This is a polymorphic method which will call the typesafe method for the node type such as remove(Element) or remove(Comment).- Parameters:
node
- is the given node to be removed- Returns:
- true if the node was removed
-
remove
Removes the givenComment
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.- Parameters:
comment
- is the comment to be removed- Returns:
- true if the comment was removed
-
remove
Removes the givenElement
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.- Parameters:
element
- is the element to be removed- Returns:
- true if the element was removed
-
remove
Removes the givenProcessingInstruction
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.- Parameters:
pi
- is the processing instruction to be removed- Returns:
- true if the processing instruction was removed
-
normalize
void 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. 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.- Since:
- DOM Level 2
-