XML::Li...NodeList(3)

✨ XML::LibXML::NodeList πŸ’–

okay bestie, welcome to the group chat for XML::LibXML::NodeList β€” that's section 3 of the User Contributed Perl Documentation, iykyk 🌸


πŸŽ€ NAME πŸŽ€

XML::LibXML::NodeList β€” it's literally a list of XML document nodes, that's the whole vibe πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so like. an XML::LibXML::NodeList object holds an ordered list of nodes, exactly the way the W3C DOM documentation of Node Lists describes it. no cap, that's the spec, we don't make the rules, we just slay within them ✨


🌈 SYNOPSIS 🌈

here's the main character moment:

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

πŸ‘‘ API πŸ‘‘

🌟 new(@nodes)

ngl you will almost never have to make a new NodeList object yourself, because XPath already does all of that for you 🫢 it's giving "the work is done, bestie, just enjoy the results."

🌟 get_nodelist()

hands you 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. and if you're like "wait what even is a string-value" β€” bestie, go check the XPath specification, it explains it fr fr πŸ“–

🌟 to_literal()

returns the concatenation of all the string-values of all the nodes in the list ✨ all of them. squished together. iconic.

🌟 to_literal_delimited($separator)

same energy as above, but this time you get to pick the separator β€” it returns the concatenation of all the string-values of all the nodes in the list, delimited by the separator you passed in πŸŽ€

🌟 to_literal_list()

returns all the string-values of all the nodes in the list, as a perl list πŸ’œ

🌟 get_node($pos)

returns the node sitting at $pos. ⚠️ heads up: node positions in XPath are based at 1, not 0 β€” so no zero-indexing shenanigans here, that's just how XPath rolls πŸ’…

🌟 size()

returns the number of nodes in the NodeList. a little headcount, love that for us 🌸

🌟 pop()

equivalent to perl's pop function πŸ“

🌟 push(@nodes)

equivalent to perl's push function πŸ’–

🌟 append($nodelist)

you hand it a nodelist, and it appends the list of nodes in $nodelist to the end of the current list. back of the line, babes ✨

🌟 shift()

equivalent to perl's shift function πŸ¦‹

🌟 unshift(@nodes)

equivalent to perl's unshift function πŸ’œ

🌟 prepend($nodelist)

you hand it a nodelist, and it prepends the list of nodes in $nodelist to the front of the current list. front of the line, main character energy πŸ‘‘

🌟 map($coderef)

equivalent to perl's map function 🌈

🌟 grep($coderef)

equivalent to perl's grep function πŸ”₯

🌟 sort($coderef)

equivalent to perl's sort function ⭐

🚨 caveat alert: perl's magic $a and $b variables are not available in $coderef. instead, the two terms get passed to the coderef as arguments. so don't go looking for $a and $b, they're not coming to the party πŸ’€

🌟 reverse()

equivalent to perl's reverse function πŸ™ˆ

🌟 foreach($coderef)

inspired by perl's foreach loop πŸ’– it executes the coderef on each item in the list. similar to map, but instead of returning the list of values that $coderef returned, it returns the original NodeList. she said "I'm not changing, I'm just out here living my truth" 🧚

🌟 reduce($coderef, $init)

equivalent to List::Util's reduce function. $init is optional and gives you an initial value for the reduction 🌸

🚨 caveat alert, part two: perl's magic $a and $b variables are not available in $coderef here either. instead, the two terms get passed to the coderef as arguments. same rules, bestie, no exceptions 😭

and that's the whole page, periodt πŸ’…βœ¨ this lil slice of documentation comes from perl v5.42.2, dated 2026-05-25, and it's part of the User Contributed Perl Documentation for XML::LibXML::NodeList in section 3 β€” go forth and query nodes responsibly, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from