Package groovy.util

Class NodeList

All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess

public class NodeList extends ArrayList
A List implementation which is returned by queries on a Node which provides some XPath like helper methods for GPath.
See Also:
  • Constructor Details

    • NodeList

      public NodeList()
      Creates an empty node list.
    • NodeList

      public NodeList(Collection collection)
      Creates a node list containing the supplied elements.
      Parameters:
      collection - the initial elements
    • NodeList

      public NodeList(int size)
      Creates an empty node list with the supplied initial capacity.
      Parameters:
      size - the initial capacity
  • Method Details

    • clone

      public Object clone()
      Creates a new NodeList containing the same elements as the original (but cloned in the case of Nodes).
      Overrides:
      clone in class ArrayList
      Returns:
      the clone
    • setMetaClass

      protected static void setMetaClass(Class nodeListClass, MetaClass metaClass)
      Installs the metaclass used for property and attribute shortcuts on node lists.
      Parameters:
      nodeListClass - the class whose metaclass should be replaced
      metaClass - the original metaclass
    • getAt

      public NodeList getAt(String name)
      Provides lookup of elements by non-namespaced name.
      Parameters:
      name - the name or shortcut key for nodes of interest
      Returns:
      the nodes of interest which match name
    • getAt

      public NodeList getAt(QName name)
      Provides lookup of elements by QName.
      Parameters:
      name - the name or shortcut key for nodes of interest
      Returns:
      the nodes of interest which match name
    • text

      public String text()
      Returns the text value of all of the elements in the collection.
      Returns:
      the text value of all the elements in the collection or null
    • replaceNode

      public Node replaceNode(Closure c)
      Replaces the sole node in this list using the supplied builder closure.
      Parameters:
      c - the closure defining replacement nodes
      Returns:
      the original node that was replaced
    • plus

      public void plus(Closure c)
      Appends sibling nodes after each node in this list.
      Parameters:
      c - the closure defining the sibling nodes