1XML::XQL::Query(3)    User Contributed Perl Documentation   XML::XQL::Query(3)
2
3
4

NAME

6       XML::XQL::Query - Creates an XQL query evaluater from a XQL expression
7

SYNOPSIS

9        use XML::XQL;
10        use XML::XQL::DOM;
11
12        $parser = new XML::DOM::Parser;
13        $doc = $parser->parsefile ("file.xml");
14
15        # Return all elements with tagName='title' under the root element 'book'
16        $query = new XML::XQL::Query (Expr => "book/title");
17        @result = $query->solve ($doc);
18
19        # Or (to save some typing)
20        @result = XML::XQL::solve ("book/title", $doc);
21

DESCRIPTION

23       To perform XQL queries on an XML::DOM document (or, in the future, on
24       other XML storage structures), you first have to create an
25       XML::XQL::Query object and pass it a valid XQL query expression. You
26       can then perform queries on one or more documents by calling the
27       solve() method.
28

XML::XQL::Query constructor

30       Usage, e.g:
31
32        $query = new XML::XQL::Query(
33               Expr => "book/author",
34               Func => [ myfunc => \&my_func,          # define 2 functions
35                         myfunc2 => \&my_func2 ],
36               FuncArgCount => [ myfunc2 => [2, -1] ], # myfunc2 has 2 or more args
37               AllowedOutSideSubquery => [ myfunc => 1 ],
38               ConstFunc => [ myfunc2 => 1],
39               CompareOper => [ mycmp => \&mycmp ],    # define comparison operator
40               q => "str");                            # use str// as string delim
41
42       Expr => STRING
43           The query expression to be evaluated.
44
45       NodeQuery => BOOLEAN
46           If set to 1, the query is a Node Query as opposed to a Full Query
47           (which is the default.)  A node query is a query that is only
48           capable of returning Nodes.  A full query is capable of returning
49           Node values and non-Node values.  Non-Node values include XML
50           Primitives, element type names, namespace URI's, concatenated text
51           nodes, and node type names. The distinction is significant because
52           node queries may appear as XSL match and select patterns, while
53           full queries have use in other applications.  The difference
54           between the two forms of queries is trivial and exists only as
55           constraints on the syntax of node queries.  Node queries may
56           contain nested full queries.
57
58       Func => [ FUNCNAME => FUNCREF, ...]
59           Defines one or more functions. FUNCNAME is the name as used in the
60           query expression. FUNCREF can be either a function reference like
61           \&my_func or an anonymous sub.  See also: defineFunction
62
63       Method => [ FUNCNAME => FUNCREF, ...]
64           Defines one or more methods. FUNCNAME is the name as used in the
65           query expression. FUNCREF can be either a function reference like
66           \&my_func or an anonymous sub.  See also: defineMethod
67
68       FuncArgCount => [ FUNCNAME => ARGCOUNT, ...]
69           Defines the number of arguments for one or more functions or
70           methods.  FUNCNAME is the name as used in the query expression.
71           See also: defineFunction and defineMethod
72
73       AllowedOutsideSubquery => [ FUNCNAME => BOOLEAN, ...]
74           Defines whether the specified function or method is allowed outside
75           subqueries. FUNCNAME is the name as used in the query expression.
76           See also: defineFunction and defineMethod
77
78       ConstFunc => [ FUNCNAME => BOOLEAN, ...]
79           Defines whether the function (not method!) is a "constant"
80           function.  FUNCNAME is the name as used in the query expression.
81           See "Constant Function Invocations" for a definition of "constant"
82           See also: defineFunction and defineMethod
83
84       CompareOper => [ OPERNAME => FUNCREF, ...]
85           Defines the comparison operator with the specified OPERNAME, e.g.
86           if OPERNAME is "contains", you can use "$contains$" in the query.
87           See also: defineComparisonOperators
88
89       q => TOKEN
90           Defines the q// token. See also: defineTokenQ
91
92       qq => TOKEN
93           Defines the qq// token. See also: defineTokenQQ
94
95       Error => FUNCREF
96           Defines the function that is called when errors occur during
97           parsing the query expression. The default function prints an error
98           message to STDERR.
99
100       Debug => FLAGS
101           Sets the debug level for the Yapp parser that parses the query
102           expression.  Default value is 0 (don't print anything). The maximum
103           value is 0x17, which prints a lot of stuff. See the Parse::Yapp
104           manpage for the meaning of the individual bits.
105
106       Reserved hash keys
107           Users may add their own (key, value) pairs to the Query
108           constructor.  Beware that the key 'Tree' is used internally.
109

XML::XQL::Query methods

111       solve (INPUT_LIST...)
112           Note that solve takes a list of nodes which are assumed to be in
113           document order and must belong to the same document. E.g:
114
115            $query = new XML::XQL::Query (Expr => "doc//book");
116            @result = $query->solve ($doc);
117            @result2 = $query->solve ($node1, $node2, $node3);
118
119       The following functions are also available at the query level, i.e.
120       when called on a Query object they only affect this Query and no
121       others:
122
123        defineFunction, defineMethod, defineComparisonOperators,
124        defineTokenQ, defineTokenQQ
125
126       See Global functions for details.  Another way to define these features
127       for a particular Query is by passing the appropriate values to the
128       XML::XQL::Query constructor.
129

SEE ALSO

131       XML::XQL for general information about the XML::XQL module
132
133       XML::XQL::Tutorial which describes the XQL syntax
134
135
136
137perl v5.30.0                      2019-07-26                XML::XQL::Query(3)
Impressum