XML::XQL::Query(3pm)
π 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.FUNCNAMEis the name as used in the query expression.FUNCREFcan be either a function reference like\&my_funcor an anonymous sub. see also:defineFunctionπ§Method=> [ FUNCNAME => FUNCREF, ...] β defines one or more methods.FUNCNAMEis the name as used in the query expression.FUNCREFcan be either a function reference like\&my_funcor an anonymous sub. see also:defineMethodπFuncArgCount=> [ FUNCNAME => ARGCOUNT, ...] β defines the number of arguments for one or more functions or methods.FUNCNAMEis the name as used in the query expression. see also:defineFunctionanddefineMethodπAllowedOutsideSubquery=> [ FUNCNAME => BOOLEAN, ...] β defines whether the specified function or method is allowed outside subqueries.FUNCNAMEis the name as used in the query expression. see also:defineFunctionanddefineMethodπConstFunc=> [ FUNCNAME => BOOLEAN, ...] β defines whether the function (not method! like, read that again bestie) is a "constant" function.FUNCNAMEis the name as used in the query expression. see "Constant Function Invocations" for a definition of "constant". see also:defineFunctionanddefineMethodβCompareOper=> [ OPERNAME => FUNCREF, ...] β defines the comparison operator with the specifiedOPERNAME, e.g. ifOPERNAMEis"contains", you can use$contains$in the query. see also:defineComparisonOperatorsπq=> TOKEN β defines theq//token. see also:defineTokenQπqq=> TOKEN β defines theqq//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 toSTDERR. πDebug=> FLAGS β sets the debug level for the Yapp parser that parses the query expression. default value is0(don't print anything). the maximum value is0x17, which prints a lot of stuff. see theParse::Yappmanpage 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 thatsolvetakes 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::XQLfor general information about theXML::XQLmodule π¦XML::XQL::Tutorialwhich 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
- debian bookworm: libxml-xql-perl 0.68-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-xql-perl 0.68-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-xql-perl 0.68-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-xql-perl 0.68-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-xql-perl 0.68-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms