mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-19 18:38:55 +00:00

- All id attributes are now xml:id - Add docbook namespace to all root elements - Replace <ulink /> with <link xlink:href /> - Minor markup fixes here and there git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@238160 c90b9560-bf6c-de11-be94-00142212c4b1
155 lines
3.9 KiB
XML
155 lines
3.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.11 $ -->
|
|
<refentry xml:id="function.dom-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;
|
|
<classsynopsis>
|
|
<ooclass><classname>DOMXPath</classname></ooclass>
|
|
<methodsynopsis>
|
|
<type>DOMNodeList</type><methodname>query</methodname>
|
|
<methodparam><type>string</type><parameter>expression</parameter></methodparam>
|
|
<methodparam choice="opt"><type>DOMNode</type><parameter>contextnode</parameter></methodparam>
|
|
</methodsynopsis>
|
|
</classsynopsis>
|
|
<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>
|
|
</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 do
|
|
not return nodes will return an empty <classname>DOMNodeList</classname>.
|
|
</para>
|
|
</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('book.xml');
|
|
|
|
$xpath = new DOMXPath($doc);
|
|
|
|
// We starts 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('book.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><xref linkend="function.dom-domxpath-evaluate" /></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:"../../../../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
|
|
-->
|