XML::XQL::Query(3pm)

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

πŸ’– XML::XQL::Query ✨

okay bestie, welcome to the User Contributed Perl Documentation page for XML::XQL::Query β€” she's the one that creates an XQL query evaluater from a XQL expression. yes, "evaluater". we don't fix it, we respect it. periodt. πŸ’…


🌸 SYNOPSIS 🌸

like, here's the whole vibe in one go:

use XML::XQL;
use XML::XQL::DOM;

$parser = new XML::DOM::Parser;
$doc = $parser->parsefile ("file.xml");

# Return all elements with tagName='title' under the root element 'book'
$query = new XML::XQL::Query (Expr => "book/title");
@result = $query->solve ($doc);

# Or (to save some typing)
@result = XML::XQL::solve ("book/title", $doc);

no cap, that second one is the lazy-girlie shortcut and she ATE. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the whole situation is this: to perform XQL queries on an XML::DOM document β€” or, in the future, on other XML storage structures, (she's manifesting πŸ’­) β€” you first have to create an XML::XQL::Query object and pass it a valid XQL query expression. then you can perform queries on one or more documents by calling the solve() method. that's it. that's the plot. πŸ”₯


πŸŽ€ XML::XQL::Query constructor

usage, e.g:

$query = new XML::XQL::Query(
       Expr => "book/author",
       Func => [ myfunc => \&my_func,          # define 2 functions
                 myfunc2 => \&my_func2 ],
       FuncArgCount => [ myfunc2 => [2, -1] ], # myfunc2 has 2 or more args
       AllowedOutSideSubquery => [ myfunc => 1 ],
       ConstFunc => [ myfunc2 => 1],
       CompareOper => [ mycmp => \&mycmp ],    # define comparison operator
       q => "str");                            # use str// as string delim
  • Expr => STRING β€” the query expression to be evaluated. like, the actual thing you're asking. πŸ‘‘
  • NodeQuery => BOOLEAN β€” if you set this to 1, the query is a Node Query as opposed to a Full Query (which is the default). a node query is a query that is only capable of returning Nodes. a full query is capable of returning Node values and non-Node values. non-Node values include XML Primitives, element type names, namespace URI's, concatenated text nodes, and node type names. the distinction is significant because node queries may appear as XSL match and select patterns, while full queries have use in other applications. the difference between the two forms of queries is trivial and exists only as constraints on the syntax of node queries. node queries may contain nested full queries. ✨
  • Func => [ FUNCNAME => FUNCREF, ...] β€” defines one or more functions. FUNCNAME is the name as used in the query expression. FUNCREF can be either a function reference like \&my_func or an anonymous sub. see also: defineFunction 🧚
  • Method => [ FUNCNAME => FUNCREF, ...] β€” defines one or more methods. FUNCNAME is the name as used in the query expression. FUNCREF can be either a function reference like \&my_func or an anonymous sub. see also: defineMethod πŸ’œ
  • FuncArgCount => [ FUNCNAME => ARGCOUNT, ...] β€” defines the number of arguments for one or more functions or methods. FUNCNAME is the name as used in the query expression. see also: defineFunction and defineMethod πŸ“
  • AllowedOutsideSubquery => [ FUNCNAME => BOOLEAN, ...] β€” defines whether the specified function or method is allowed outside subqueries. FUNCNAME is the name as used in the query expression. see also: defineFunction and defineMethod 🌈
  • ConstFunc => [ FUNCNAME => BOOLEAN, ...] β€” defines whether the function (not method! like, read that again bestie) is a "constant" function. FUNCNAME is the name as used in the query expression. see "Constant Function Invocations" for a definition of "constant". see also: defineFunction and defineMethod ⭐
  • CompareOper => [ OPERNAME => FUNCREF, ...] β€” defines the comparison operator with the specified OPERNAME, e.g. if OPERNAME is "contains", you can use $contains$ in the query. see also: defineComparisonOperators πŸ’…
  • q => TOKEN β€” defines the q// token. see also: defineTokenQ πŸŽ€
  • qq => TOKEN β€” defines the qq// token. see also: defineTokenQQ πŸŽ€
  • Error => FUNCREF β€” defines the function that is called when errors occur during parsing the query expression. the default function prints an error message to STDERR. 😭
  • Debug => FLAGS β€” sets the debug level for the Yapp parser that parses the query expression. default value is 0 (don't print anything). the maximum value is 0x17, which prints a lot of stuff. see the Parse::Yapp manpage for the meaning of the individual bits. πŸ’€
  • Reserved hash keys β€” users may add their own (key, value) pairs to the Query constructor. beware that the key 'Tree' is used internally. do not touch her. she's busy. πŸ™ˆ

πŸ‘‘ XML::XQL::Query methods πŸ‘‘

  • solve (INPUT_LIST...) β€” ngl, note that solve takes a list of nodes which are assumed to be in document order and must belong to the same document. e.g:
$query = new XML::XQL::Query (Expr => "doc//book");
@result = $query->solve ($doc);
@result2 = $query->solve ($node1, $node2, $node3);

the following functions are also available at the query level, i.e. when called on a Query object they only affect this Query and no others:

defineFunction, defineMethod, defineComparisonOperators,
defineTokenQ, defineTokenQQ

see Global functions for details. another way to define these features for a particular Query is by passing the appropriate values to the XML::XQL::Query constructor. two paths, same slay. ✨


🌟 SEE ALSO 🌟

  • XML::XQL for general information about the XML::XQL module πŸ¦‹
  • XML::XQL::Tutorial which describes the XQL syntax πŸ“–

okay that's the whole page, bestie!! this was perl v5.36.0, dated 2022-12-06 β€” vintage, honestly, she's giving classic. go forth and query. mwah πŸ’–πŸ’…βœ¨

πŸ“¦ where this page comes from