Top Description Fields Methods
org.dom4j

public Interface Branch

extends Node
Known Direct Subinterfaces
org.dom4j.Document, org.dom4j.Element
Known Direct Implementers
org.dom4j.tree.AbstractBranch
Annotations
@SuppressWarnings:unused
Imports
java.util.Iterator, .List

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).
Author
James Strachan
Version
$Revision: 1.32 $

Field Summary

Inherited from org.dom4j.Node:
ANY_NODEATTRIBUTE_NODECDATA_SECTION_NODECOMMENT_NODEDOCUMENT_NODEDOCUMENT_TYPE_NODEELEMENT_NODEENTITY_REFERENCE_NODEMAX_NODE_TYPENAMESPACE_NODEPROCESSING_INSTRUCTION_NODETEXT_NODEUNKNOWN_NODE

Method Summary

Modifier and TypeMethod and Description
public void
add(Node
is the given node to add
node
)

Adds the given Node or throws IllegalAddException if the given node is not of a valid type.

public void
add(Comment
is the comment to be added
comment
)

Adds the given Comment to this branch.

public void
add(Element
is the element to be added
element
)

Adds the given Element to this branch.

public void
add(ProcessingInstruction
is the processing instruction to be added
pi
)

Adds the given ProcessingInstruction to this branch.

public Element

Returns:

the newly added Element node.
addElement
(String
is the name for the Element node.
name
)

Adds a new Element node with the given name to this branch and returns a reference to the new node.

public Element

Returns:

the newly added Element node.
addElement
(QName
is the qualified name for the Element node.
qname
)

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.

public Element

Returns:

the newly added Element node.
addElement
(String
is the fully qualified name of the Element
qualifiedName
,
String
is the URI of the namespace to use
namespaceURI
)

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.

public void
appendContent(Branch
is the branch whose content will be added to me.
branch
)

Appends the content of the given branch to this branch instance.

public void
clearContent()

Clears the content for this branch, removing any Node instances this branch may contain.

public List<Node>

Returns:

the nodes that this branch contains as a List
content
()

Returns the content nodes of this branch as a backed Listso that the content of this branch may be modified directly using the Listinterface.

public Element

Returns:

DOCUMENT ME!
elementByID
(String
DOCUMENT ME!
elementID
)

Returns the element of the given ID attribute value.

public int

Returns:

the index of the given node starting at 0 or -1 if the node is not a child node of this branch
indexOf
(Node
the content child node to find.
node
)

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.

public Node

Returns:

the Node at the specified position.
node
(int
the index of the node to return.
index
)

Returns the Node at the specified index position.

public int

Returns:

the number of nodes this branch contains
nodeCount
()

Returns the number of Node instances that this branch contains.

public Iterator<Node>

Returns:

an iterator through the content nodes of this branch
nodeIterator
()

Returns an iterator through the content nodes of this branch

public void
normalize()

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.

public ProcessingInstruction

Returns:

the processing instruction for the given target
processingInstruction
(String
DOCUMENT ME!
target
)

DOCUMENT ME!

public List<ProcessingInstruction>

Returns:

a backed list of the processing instructions
processingInstructions
()

Returns a list of all the processing instructions in this branch.

public List<ProcessingInstruction>

Returns:

a backed list of the processing instructions
processingInstructions
(String
DOCUMENT ME!
target
)

Returns a list of the processing instructions for the given target.

public boolean

Returns:

true if the node was removed
remove
(Node
is the given node to be removed
node
)

Removes the given Node if the node is an immediate child of this branch.

public boolean

Returns:

true if the comment was removed
remove
(Comment
is the comment to be removed
comment
)

Removes the given Comment if the node is an immediate child of this branch.

public boolean

Returns:

true if the element was removed
remove
(Element
is the element to be removed
element
)

Removes the given Element if the node is an immediate child of this branch.

public boolean

Returns:

true if the processing instruction was removed
remove
(ProcessingInstruction
is the processing instruction to be removed
pi
)

Removes the given ProcessingInstruction if the node is an immediate child of this branch.

public boolean

Returns:

true if a processing instruction was removed else false
removeProcessingInstruction
(String
DOCUMENT ME!
target
)

Removes the processing instruction for the given target if it exists

public void
setContent(List<Node>
is the list of nodes to use as the content for this branch.
content
)

Sets the contents of this branch as a List of Node instances.

public void
setProcessingInstructions(List<ProcessingInstruction>
DOCUMENT ME!
listOfPIs
)

Sets all the processing instructions for this branch

Inherited from org.dom4j.Node:
acceptasXMLasXPathResultclonecreateXPathdetachgetDocumentgetNamegetNodeTypegetNodeTypeNamegetParentgetPathgetPathgetStringValuegetTextgetUniquePathgetUniquePathhasContentisReadOnlymatchesnumberValueOfselectNodesselectNodesselectNodesselectObjectselectSingleNodesetDocumentsetNamesetParentsetTextsupportsParentvalueOfwrite

Method Detail

addback to summary
public void add(Node node)

Adds the given Node or throws IllegalAddException 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:Node

is the given node to add

addback to summary
public void add(Comment comment)

Adds the given Comment to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
comment:Comment

is the comment to be added

addback to summary
public void add(Element element)

Adds the given Element to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
element:Element

is the element to be added

addback to summary
public void add(ProcessingInstruction pi)

Adds the given ProcessingInstruction to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
pi:ProcessingInstruction

is the processing instruction to be added

addElementback to summary
public Element addElement(String name)

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Parameters
name:String

is the name for the Element node.

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(QName qname)

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.

Parameters
qname:QName

is the qualified name for the Element node.

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(String qualifiedName, String namespaceURI)

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.

Parameters
qualifiedName:String

is the fully qualified name of the Element

namespaceURI:String

is the URI of the namespace to use

Returns:Element

the newly added Element node.

appendContentback to summary
public void appendContent(Branch branch)

Appends the content of the given branch to this branch instance. This method behaves like the java.util.Collection#addAll(java.util.Collection) method.

Parameters
branch:Branch

is the branch whose content will be added to me.

clearContentback to summary
public void clearContent()

Clears the content for this branch, removing any Node instances this branch may contain.

contentback to summary
public List<Node> content()

Returns the content nodes of this branch as a backed Listso that the content of this branch may be modified directly using the Listinterface. The List is backed by the Branch so that changes to the list are reflected in the branch and vice versa.

Returns:List<Node>

the nodes that this branch contains as a List

elementByIDback to summary
public Element elementByID(String elementID)

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:String

DOCUMENT ME!

Returns:Element

DOCUMENT ME!

indexOfback to summary
public int indexOf(Node node)

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:Node

the content child node to find.

Returns:int

the index of the given node starting at 0 or -1 if the node is not a child node of this branch

nodeback to summary
public Node node(int index) throws IndexOutOfBoundsException

Returns the Node at the specified index position.

Parameters
index:int

the index of the node to return.

Returns:Node

the Node at the specified position.

Exceptions
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= Branch#nodeCount()).
nodeCountback to summary
public int nodeCount()

Returns the number of Node instances that this branch contains.

Returns:int

the number of nodes this branch contains

nodeIteratorback to summary
public Iterator<Node> nodeIterator()

Returns an iterator through the content nodes of this branch

Returns:Iterator<Node>

an iterator through the content nodes of this branch

normalizeback to summary
public void normalize()

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text 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 contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

Since
DOM Level 2
processingInstructionback to summary
public ProcessingInstruction processingInstruction(String target)

DOCUMENT ME!

Parameters
target:String

DOCUMENT ME!

Returns:ProcessingInstruction

the processing instruction for the given target

processingInstructionsback to summary
public 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:List<ProcessingInstruction>

a backed list of the processing instructions

processingInstructionsback to summary
public List<ProcessingInstruction> processingInstructions(String target)

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:String

DOCUMENT ME!

Returns:List<ProcessingInstruction>

a backed list of the processing instructions

removeback to summary
public boolean remove(Node node)

Removes the given Node if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#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:Node

is the given node to be removed

Returns:boolean

true if the node was removed

removeback to summary
public boolean remove(Comment comment)

Removes the given Comment if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
comment:Comment

is the comment to be removed

Returns:boolean

true if the comment was removed

removeback to summary
public boolean remove(Element element)

Removes the given Element if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
element:Element

is the element to be removed

Returns:boolean

true if the element was removed

removeback to summary
public boolean remove(ProcessingInstruction pi)

Removes the given ProcessingInstruction if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
pi:ProcessingInstruction

is the processing instruction to be removed

Returns:boolean

true if the processing instruction was removed

removeProcessingInstructionback to summary
public boolean removeProcessingInstruction(String target)

Removes the processing instruction for the given target if it exists

Parameters
target:String

DOCUMENT ME!

Returns:boolean

true if a processing instruction was removed else false

setContentback to summary
public void setContent(List<Node> content)

Sets the contents of this branch as a List of Node instances.

Parameters
content:List<Node>

is the list of nodes to use as the content for this branch.

setProcessingInstructionsback to summary
public void setProcessingInstructions(List<ProcessingInstruction> listOfPIs)

Sets all the processing instructions for this branch

Parameters
listOfPIs:List<ProcessingInstruction>

DOCUMENT ME!