XML::XP...:NodeSet(3)

✨ NAME ✨

okay so bestie, welcome to XML::XPath::NodeSet β€” it's a list of XML document nodes πŸ’– and yeah, it lives in the User Contributed Perl Documentation manual section, section 3, iykyk πŸŽ€


🌸 DESCRIPTION 🌸

An XML::XPath::NodeSet object is literally just an ordered list of nodes, no cap πŸ’…. It's giving "glow-up for an array," fr fr.

And the nodes inside it? Every single one takes the same format as described over in XML::XPath::XMLParser β€” so if you need the deets on what a node actually looks like, that's your girl πŸ¦‹.


🫢 SYNOPSIS 🫢

here's the vibe, copy it, run it, slay:

        my $results = $xp->find('//someelement');
        if (!$results->isa('XML::XPath::NodeSet')) {
                print "Found $results\n";
                exit;
        }
        foreach my $context ($results->get_nodelist) {
                my $newresults = $xp->find('./other/element', $context);
                ...
        }

πŸ‘‘ API πŸ‘‘

the main character section, periodt.

🌈 new()

bestie you will almost never have to create a new NodeSet object yourself, because XPath handles all of that for you. it's giving "we got you" πŸ’– not me doing zero work and still getting the results 🫢

⭐ get_nodelist()

Returns a list of nodes. wanna know the format of those nodes? check XML::XPath::XMLParser, it's all laid out there 🌸

πŸ’œ string_value()

Returns the string-value of the first node in the list. and yes, if you're like "what even is a string-value" β€” go read the XPath specification, it's the whole vibe check on that term πŸ“–βœ¨

πŸŽ€ to_literal()

Returns the concatenation of all the string-values of all the nodes in the list. every single one. gluing them together like friendship bracelets 🫢

πŸ¦‹ get_node($pos)

Returns the node at $pos. and here's the tea that trips people up: the node position in XPath is based at 1, not 0 πŸ’€ so don't come at it with your zero-indexed brain, bestie, it will humble you.

πŸ“ size()

Returns the number of nodes in the NodeSet. that's it, that's the whole thing, iconic behavior πŸ‘‘

πŸ’… pop()

Equivalent to perl's pop function. yes queen, same energy, just wearing a cuter outfit ✨

🧚 push(@nodes)

Equivalent to perl's push function. nodes go in at the end, no drama 🌸

🌟 append($nodeset)

Given a nodeset, appends the list of nodes in $nodeset to the end of the current list. like adding more people to the group chat, and they're all welcome πŸ’œ

πŸ”₯ shift()

Equivalent to perl's shift function. takes from the front, lowkey always has ✨

🌈 unshift(@nodes)

Equivalent to perl's unshift function. front of the line energy, but make it perl πŸ’…

πŸ’– prepend($nodeset)

Given a nodeset, prepends the list of nodes in $nodeset to the front of the current list. main character entrance, literally πŸŽ€


and that's the whole page, bestie!! this gem is documented by perl v5.42.1, dated 2026-04-21 β€” shoutout to whoever wrote it, you ate πŸ’– mwah, go process some nodes, ily 🫢✨🌈

πŸ“¦ where this page comes from