Tree::...odeSet(3pm)

πŸ“¦
version 0.05 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Tree::XPathEngine::NodeSet πŸ’–

okay bestie, so this page is straight outta the User Contributed Perl Documentation corner of the manual-verse, and it's all about Tree::XPathEngine::NodeSet β€” a list of XML document nodes. yeah. that's the whole vibe. let's get into it πŸ¦‹


✨ NAME ✨

Tree::XPathEngine::NodeSet β€” literally just a list of XML document nodes. that's it. that's the girl. πŸ’…


🌸 DESCRIPTION 🌸

so a Tree::XPathEngine::NodeSet object is holding an ordered list of nodes. ordered. like a queue at a boba shop but with XML.

and every single node in there is formatted the exact same way as described over in Tree::XPathEngine::XMLParser. no cap, go read that one if you need the deets on the node format. πŸ“–


πŸŽ€ SYNOPSIS πŸŽ€

here's the whole moment, verbatim, no edits:

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

πŸ‘‘ API πŸ‘‘

🧚 new()

bestie you will almost never have to make a new NodeSet object yourself. XPath does it all for you, behind the scenes, like a personal assistant. let her cook. πŸ”₯

πŸ’œ get_nodelist()

hands you a list of nodes. for what a node even looks like, go check Tree::XPathEngine::XMLParser. πŸ’«

⭐ xpath_string_value()

gives you the string-value of the first node in the list. and if you're like "what is a string-value" β€” that's an XPath spec thing, the spec knows, go ask the spec. πŸ“š

🌈 xpath_to_literal()

concatenates all the string-values of all the nodes in the list and hands you the whole glooped-together result. every node. no skipping. 🫢

πŸ“ get_node($pos)

returns the node sitting at $pos. ⚠️ heads up bestie, XPath positions are 1-based, not 0-based β€” so the first node is at 1. do not come in here with your zeroes, the vibes will be off. 😭

πŸŽ€ size()

tells you how many nodes are in the NodeSet. a headcount. a roll call. πŸ“‹

πŸ’… pop()

same energy as perl's own pop function. πŸ’–

✨ push(@nodes)

same energy as perl's own push function. πŸ’–

πŸ¦‹ append($nodeset)

hand it a nodeset and it takes that nodeset's list of nodes and appends them to the end of the current list. back of the line, babes. πŸšΆβ€β™€οΈ

🌸 shift()

same energy as perl's own shift function. πŸ’–

πŸ’œ unshift(@nodes)

same energy as perl's own unshift function. πŸ’–

πŸ‘‘ prepend($nodeset)

hand it a nodeset and it takes that nodeset's list of nodes and prepends them to the front of the current list. cutting the line, but make it legal. πŸ’…

⭐ xpath_get_root_node

returns the root node of the first node in the set. going straight to the top, main character behaviour. 🧚

πŸ”₯ sort

returns a sorted nodeset, sorted using the "cmp" method on nodes. cute and orderly. ✨

πŸ’€ remove_duplicates

returns a sorted nodeset containing only unique nodes. ⚠️ but listen: the input nodeset MUST be sorted. like, that is not optional. sort it first or perish. πŸ’€

🌈 xpath_to_boolean

returns true if the nodeset is not empty. empty nodeset? false. got anything in there? true. simple as. βœ…

πŸ“ xpath_to_number

returns the concatenation of all the string-values of all the nodes in the list, as a Tree::XPathEngine::Number object; 🫢


ngl the whole point of this class is just: XPath hands you a pile of nodes, and this is the wrapper that lets you count them, sort them, dedupe them, and convert them into strings, literals, booleans and numbers. that's the tea. β˜•

okay that's the page!! and for the little sign-off moment at the bottom, shoutout to the source: this is perl v5.36.0, dated 2022-11-20. iconic. periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from