Interface ParentNode

All Superinterfaces:
CSSNode, DOMNode, Node
All Known Implementing Classes:
DOMDocument, DOMElement, HTMLDocument, HTMLElement

public interface ParentNode extends DOMNode
Based on W3C's ParentNode interface.
  • Method Details

    • getChildNodes

      DOMNodeList getChildNodes()
      Gets a DOMNodeList containing all the children of this parent node.
      Specified by:
      getChildNodes in interface DOMNode
      Specified by:
      getChildNodes in interface Node
      Returns:
      the list of child nodes, empty if there are no children.
    • getChildren

      ElementList getChildren()
      Gets the live ElementList containing all nodes of type Element that are children of this ParentNode.
      Returns:
      the ElementList containing all nodes of type Element that are children of this ParentNode.
    • getFirstElementChild

      DOMElement getFirstElementChild()
      Gets the Element that is the first child of this ParentNode.
      Returns:
      the Element that is the first child of this ParentNode, or null if there is none.
    • getLastElementChild

      DOMElement getLastElementChild()
      Gets the Element that is the last child of this ParentNode.
      Returns:
      the Element that is the last child of this ParentNode, or null if there is none.
    • getChildElementCount

      int getChildElementCount()
      Gets the number of child nodes of type Element that this parent node has.
      Returns:
      the number of child nodes of type Element that this parent node has.
    • prependChild

      DOMNode prependChild(Node newChild) throws DOMException
      Inserts the node newChild at the beginning of the list of children of this node. If the newChild is already in the tree, it is first removed.
      Parameters:
      newChild - the node to prepend. If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node.
      Returns:
      the prepended node.
      Throws:
      DOMException - HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to prepend is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to prepend a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • iterator

      Iterator<DOMNode> iterator()
      Creates a new iterator over the child nodes.
      Returns:
      an iterator over the child nodes.
    • descendingIterator

      Iterator<DOMNode> descendingIterator()
      Creates a new iterator descending over the child nodes, starting from the last child node.
      Returns:
      an iterator descending over the child nodes.
    • iterator

      Iterator<DOMNode> iterator(BitSet whatToShow)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow bit field.

      Example:

            BitSet mask = new BitSet(32);
            mask.set(Node.ELEMENT_NODE);
            Iterator<Node> it = node.iterator(mask);
       
      Parameters:
      whatToShow - a bit set.
      Returns:
      an iterator over the child nodes.
    • iterator

      Iterator<DOMNode> iterator(NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over nodes accepted by the filter.

      Parameters:
      filter - a filter, see NodeFilter.
      Returns:
      an iterator over the child nodes.
    • iterator

      Iterator<DOMNode> iterator(int whatToShow, NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow mask that satisfy the custom NodeFilter.

      Example:

       Iterator<Node> it = node.iterator(NodeFilter.SHOW_ELEMENT, null);
       
      Parameters:
      whatToShow - the bit field mask to apply to the node types, see NodeFilter. Do not confuse this argument with the short argument of the typeIterator(short) method.
      filter - the filter to use in the iteration. if null, only the whatToShow mask filter is applied.
      Returns:
      an iterator over the child nodes.
    • typeIterator

      Iterator<DOMNode> typeIterator(short typeToShow)
      Creates a new iterator over the child nodes.

      Do not confuse the typeToShow argument with the int argument of the iterator(int, NodeFilter) method, which is a bit field.

      Parameters:
      typeToShow - the node type to show (from Node.getNodeType()).
      Returns:
      an iterator over the child nodes.
    • elementIterator

      Iterator<DOMElement> elementIterator()
      Creates a new iterator over the child elements.
      Returns:
      an iterator over the child elements.
    • elementIterator

      Iterator<DOMElement> elementIterator(String name) throws DOMException
      Creates a new iterator over the child elements of the given tagname.
      Parameters:
      name - The tag name of the child elements to match on.
      Returns:
      an iterator over the child elements.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name if null or the empty string.
    • elementIteratorNS

      Iterator<DOMElement> elementIteratorNS(String namespaceURI, String localName)
      Creates a new iterator over the child elements of the given namespaceURI and localName.
      Parameters:
      namespaceURI - the namespace URI of the elements to match on.
      localName - The local name of the elements to match on.
      Returns:
      an iterator over the child elements.
    • listIterator

      NodeListIterator listIterator()
      Creates a new list iterator over the child nodes.
      Returns:
      a list iterator over the child nodes.
    • querySelectorAll

      ElementList querySelectorAll(String selectors)
      Gets a static ElementList of the descendant elements that match any of the specified list of selectors.

      Unlike methods like getElementsByTagName(String) or getElementsByClassName(String), this is not a live list but a static one, representing the state of the document when the method was called. If no elements match, the list shall be empty.

      Parameters:
      selectors - a comma-separated list of selectors.
      Returns:
      an ElementList with the elements that match any of the specified group of selectors.
    • getElementsByTagName

      ElementList getElementsByTagName(String name)
      Gives an ElementList of all the elements descending from this context node that have the given tag name, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Parameters:
      name - The tag name of the elements to match on. The special value "*" matches all tag names.
      Returns:
      the ElementList object containing all the matched elements.
    • getElementsByTagNameNS

      ElementList getElementsByTagNameNS(String namespaceURI, String localName)
      Gives an ElementList of all the elements descending from this context node that have the given local name and namespace URI, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Parameters:
      namespaceURI - the namespace URI of the elements to match on. The special value "*" matches all namespaces.
      localName - The local name of the elements to match on. The special value "*" matches all local names.
      Returns:
      the ElementList object containing all the matched elements.
    • getElementsByClassName

      ElementList getElementsByClassName(String names)
      Gives a live ElementList containing all the descending elements which have all of the given class names under this reference node.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Parameters:
      names - the names of the classes, separated by whitespace.
      Returns:
      the live ElementList containing all the descending elements which have all of the given class names under this reference node.