php-doc-en/reference/dom/functions/dom-domxpath-evaluate.xml

123 lines
3 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<refentry id="function.dom-domxpath-evaluate">
<refnamediv>
<refname>DOMXPath->evaluate()</refname>
<refpurpose>
Evaluates the given XPath expression and returns a typed result if possible.
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<classsynopsis>
<ooclass><classname>DOMXPath</classname></ooclass>
<methodsynopsis>
<type>mixed</type>
<methodname>evaluate</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> and returns
a typed result if possible.
</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 typed result if possible or a <classname>DOMNodeList</classname>
containing all nodes matching the given XPath <parameter>expression</parameter>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Getting the count of all the english books</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
$doc->load('book.xml');
$xpath = new DOMXPath($doc);
$tbody = $doc->getElementsByTagName('tbody')->item(0);
// our query is relative to the tbody node
$query = 'count(row/entry[. = "en"])';
$entries = $xpath->evaluate($query, $tbody);
echo "There are $entries english books\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
There are 2 english books
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><xref linkend="function.dom-domxpath-query" /></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
-->