Package org.dom4j

Interface Branch

    • Method Detail

      • indexOf

        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 - 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 of Node instances that this branch contains.
        Returns:
        the number of nodes this branch contains
      • elementByID

        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 - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • content

        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:
        the nodes that this branch contains as a List
      • nodeIterator

        Iterator<Node> nodeIterator()
        Returns an iterator through the content nodes of this branch
        Returns:
        an iterator through the content nodes of this branch
      • setContent

        void setContent​(List<Node> content)
        Sets the contents of this branch as a List of Node instances.
        Parameters:
        content - is the list of nodes to use as the content for this branch.
      • appendContent

        void appendContent​(Branch branch)
        Appends the content of the given branch to this branch instance. This method behaves like the Collection.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 any Node 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

        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 - DOCUMENT ME!
        Returns:
        a backed list of the processing instructions
      • processingInstruction

        ProcessingInstruction processingInstruction​(String target)
        DOCUMENT ME!
        Parameters:
        target - DOCUMENT ME!
        Returns:
        the processing instruction for the given target
      • setProcessingInstructions

        void setProcessingInstructions​(List<ProcessingInstruction> listOfPIs)
        Sets all the processing instructions for this branch
        Parameters:
        listOfPIs - DOCUMENT ME!
      • addElement

        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 - is the name for the Element node.
        Returns:
        the newly added Element node.
      • addElement

        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 - is the qualified name for the Element node.
        Returns:
        the newly added Element node.
      • addElement

        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 - is the fully qualified name of the Element
        namespaceURI - is the URI of the namespace to use
        Returns:
        the newly added Element node.
      • removeProcessingInstruction

        boolean removeProcessingInstruction​(String target)
        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

        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 - is the given node to add
      • add

        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 - is the comment to be added
      • add

        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 - is the element to be added
      • add

        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 - is the processing instruction to be added
      • remove

        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 - is the given node to be removed
        Returns:
        true if the node was removed
      • remove

        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 - is the comment to be removed
        Returns:
        true if the comment was removed
      • remove

        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 - is the element to be removed
        Returns:
        true if the element was removed
      • remove

        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 - is the processing instruction to be removed
        Returns:
        true if the processing instruction was removed
      • normalize

        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