-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathquery.xml
188 lines (174 loc) · 5.08 KB
/
query.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="domxpath.query" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>DOMXPath::query</refname>
<refpurpose>
Evaluates the given XPath expression
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="DOMXPath">
<modifier>public</modifier> <type>mixed</type><methodname>DOMXPath::query</methodname>
<methodparam><type>string</type><parameter>expression</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>DOMNode</type><type>null</type></type><parameter>contextNode</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>registerNodeNS</parameter><initializer>&true;</initializer></methodparam>
</methodsynopsis>
<para>
Executes the given XPath <parameter>expression</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>expression</parameter></term>
<listitem>
<para>
The XPath expression to execute.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>contextNode</parameter></term>
<listitem>
<para>
The optional <parameter>contextNode</parameter> can be specified for
doing relative XPath queries. By default, the queries are relative to
the root element.
</para>
</listitem>
</varlistentry>
&dom.parameters.register_node_ns;
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a <classname>DOMNodeList</classname> containing all nodes matching
the given XPath <parameter>expression</parameter>. Any expression which
does not return nodes will return an empty
<classname>DOMNodeList</classname>.
</para>
<para>
If the <parameter>expression</parameter> is malformed or the
<parameter>contextNode</parameter> is invalid,
<methodname>DOMXPath::query</methodname> returns &false;.
</para>
</refsect1>
<refsect1 role="errors" xml:id="domxpath.query..errors">
&reftitle.errors;
<simpara>
The following errors are possible when using an expression that invokes
PHP callbacks.
</simpara>
<itemizedlist>
<listitem>
<simpara>
Throws an <exceptionname>Error</exceptionname> if
a PHP callback is invoked but there were no callbacks registered,
or if the named callback was not registered.
</simpara>
</listitem>
<listitem>
<simpara>
Throws a <exceptionname>TypeError</exceptionname> if
the <literal>php:function</literal> syntax is used and the handler
name is not a string.
</simpara>
</listitem>
<listitem>
<simpara>
Throws an <exceptionname>Error</exceptionname> if
a non-DOM object was returned from a callback.
</simpara>
</listitem>
</itemizedlist>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Getting all the english books</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;
$doc->load('examples/book-docbook.xml');
$xpath = new DOMXPath($doc);
// We start from the root element
$query = '//book/chapter/para/informaltable/tgroup/tbody/row/entry[. = "en"]';
$entries = $xpath->query($query);
foreach ($entries as $entry) {
echo "Found {$entry->previousSibling->previousSibling->nodeValue}," .
" by {$entry->previousSibling->nodeValue}\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Found The Grapes of Wrath, by John Steinbeck
Found The Pearl, by John Steinbeck
]]>
</screen>
<para>
We can also use the <parameter>contextNode</parameter> parameter to shorten
our expression:
</para>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->load('examples/book-docbook.xml');
$xpath = new DOMXPath($doc);
$tbody = $doc->getElementsByTagName('tbody')->item(0);
// our query is relative to the tbody node
$query = 'row/entry[. = "en"]';
$entries = $xpath->query($query, $tbody);
foreach ($entries as $entry) {
echo "Found {$entry->previousSibling->previousSibling->nodeValue}," .
" by {$entry->previousSibling->nodeValue}\n";
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>DOMXPath::evaluate</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->