XML::LibXML::NodeList(3) User Contributed Perl Documentation XML::LibXML::NodeList(3)

# [NAME](#NAME)

XML::LibXML::NodeList - a list of XML document nodes

# [DESCRIPTION](#DESCRIPTION)

An XML::LibXML::NodeList object contains an ordered list of nodes, as detailed by the W3C DOM documentation of Node Lists.

# [SYNOPSIS](#SYNOPSIS)

```
  my $results = $dom->findnodes('//somepath');
  foreach my $context ($results->get_nodelist) {
    my $newresults = $context->findnodes('./other/element');
    ...
  }
```

# [API](#API)

## [new(@nodes)](#new%28@nodes%29)

You will almost never have to create a new NodeList object, as it is all done for you by XPath.

## **get\_nodelist()**

Returns a list of nodes, the contents of the node list, as a perl list.

## **string\_value()**

Returns the string-value of the first node in the list. See the XPath specification for what "string-value" means.

## **to\_literal()**

Returns the concatenation of all the string-values of all the nodes in the list.

## [to\_literal\_delimited($separator)](#to_literal_delimited%28$separator%29)

Returns the concatenation of all the string-values of all the nodes in the list, delimited by the specified separator.

## **to\_literal\_list()**

Returns all the string-values of all the nodes in the list as a perl list.

## [get\_node($pos)](#get_node%28$pos%29)

Returns the node at $pos. The node position in XPath is based at 1, not 0.

## **size()**

Returns the number of nodes in the NodeList.

## **pop()**

Equivalent to perl's pop function.

## [push(@nodes)](#push%28@nodes%29)

Equivalent to perl's push function.

## [append($nodelist)](#append%28$nodelist%29)

Given a nodelist, appends the list of nodes in $nodelist to the end of the current list.

## **shift()**

Equivalent to perl's shift function.

## [unshift(@nodes)](#unshift%28@nodes%29)

Equivalent to perl's unshift function.

## [prepend($nodelist)](#prepend%28$nodelist%29)

Given a nodelist, prepends the list of nodes in $nodelist to the front of the current list.

## [map($coderef)](#map%28$coderef%29)

Equivalent to perl's map function.

## [grep($coderef)](#grep%28$coderef%29)

Equivalent to perl's grep function.

## [sort($coderef)](#sort%28$coderef%29)

Equivalent to perl's sort function.

Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments.

## **reverse()**

Equivalent to perl's reverse function.

## [foreach($coderef)](#foreach%28$coderef%29)

Inspired by perl's foreach loop. Executes the coderef on each item in the list. Similar to "map", but instead of returning the list of values returned by $coderef, returns the original NodeList.

## [reduce($coderef, $init)](#reduce%28$coderef,_$init%29)

Equivalent to List::Util's reduce function. $init is optional and provides an initial value for the reduction.

Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments.

2026-08-28 perl v5.44.0

---

Document: XML::LibXML::NodeList(3pm) from perl-xml-libxml 2.0212-r3 (Chainguard OS)
Source: https://github.com/shlomif/perl-XML-LibXML
