|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.524 2010/08/05 18:21:17 tgl Exp $ --> |
|
|
|
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.525 2010/08/08 19:15:27 tgl Exp $ --> |
|
|
|
|
|
|
|
|
|
<chapter id="functions"> |
|
|
|
|
<title>Functions and Operators</title> |
|
|
|
@ -8175,7 +8175,7 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple |
|
|
|
|
linkend="datatype-xml"> for information about the <type>xml</type> |
|
|
|
|
type. The function-like expressions <function>xmlparse</function> |
|
|
|
|
and <function>xmlserialize</function> for converting to and from |
|
|
|
|
type <type>xml</type> are not repeated here. Use of many of these |
|
|
|
|
type <type>xml</type> are not repeated here. Use of most of these |
|
|
|
|
functions requires the installation to have been built |
|
|
|
|
with <command>configure --with-libxml</>. |
|
|
|
|
</para> |
|
|
|
@ -8636,7 +8636,8 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
To process values of data type <type>xml</type>, PostgreSQL offers |
|
|
|
|
the function <function>xpath</function>, which evaluates XPath 1.0 |
|
|
|
|
the functions <function>xpath</function> and |
|
|
|
|
<function>xpath_exists</function>, which evaluate XPath 1.0 |
|
|
|
|
expressions. |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
@ -8646,7 +8647,8 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
The function <function>xpath</function> evaluates the XPath |
|
|
|
|
expression <replaceable>xpath</replaceable> against the XML value |
|
|
|
|
expression <replaceable>xpath</replaceable> (a <type>text</> value) |
|
|
|
|
against the XML value |
|
|
|
|
<replaceable>xml</replaceable>. It returns an array of XML values |
|
|
|
|
corresponding to the node set produced by the XPath expression. |
|
|
|
|
</para> |
|
|
|
@ -8657,13 +8659,13 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
The third argument of the function is an array of namespace |
|
|
|
|
mappings. This array should be a two-dimensional array with the |
|
|
|
|
length of the second axis being equal to 2 (i.e., it should be an |
|
|
|
|
The optional third argument of the function is an array of namespace |
|
|
|
|
mappings. This array should be a two-dimensional <type>text</> array with |
|
|
|
|
the length of the second axis being equal to 2 (i.e., it should be an |
|
|
|
|
array of arrays, each of which consists of exactly 2 elements). |
|
|
|
|
The first element of each array entry is the namespace name (alias), the |
|
|
|
|
second the namespace URI. It is not required that aliases provided in |
|
|
|
|
this array are the same that those being used in the XML document itself (in |
|
|
|
|
this array be the same as those being used in the XML document itself (in |
|
|
|
|
other words, both in the XML document and in the <function>xpath</function> |
|
|
|
|
function context, aliases are <emphasis>local</>). |
|
|
|
|
</para> |
|
|
|
@ -8682,7 +8684,7 @@ SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>', |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
How to deal with default (anonymous) namespaces: |
|
|
|
|
To deal with default (anonymous) namespaces, do something like this: |
|
|
|
|
<screen><![CDATA[ |
|
|
|
|
SELECT xpath('//mydefns:b/text()', '<a xmlns="http://example.com"><b>test</b></a>', |
|
|
|
|
ARRAY[ARRAY['mydefns', 'http://example.com']]); |
|
|
|
@ -8691,6 +8693,36 @@ SELECT xpath('//mydefns:b/text()', '<a xmlns="http://example.com"><b>test</b></a |
|
|
|
|
-------- |
|
|
|
|
{test} |
|
|
|
|
(1 row) |
|
|
|
|
]]></screen> |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<indexterm> |
|
|
|
|
<primary>xpath_exists</primary> |
|
|
|
|
</indexterm> |
|
|
|
|
|
|
|
|
|
<synopsis> |
|
|
|
|
<function>xpath_exists</function>(<replaceable>xpath</replaceable>, <replaceable>xml</replaceable> <optional>, <replaceable>nsarray</replaceable></optional>) |
|
|
|
|
</synopsis> |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
The function <function>xpath_exists</function> is a specialized form |
|
|
|
|
of the <function>xpath</function> function. Instead of returning the |
|
|
|
|
individual XML values that satisfy the XPath, this function returns a |
|
|
|
|
boolean indicating whether the query was satisfied or not. This |
|
|
|
|
function is equivalent to the standard <literal>XMLEXISTS</> predicate, |
|
|
|
|
except that it also offers support for a namespace mapping argument. |
|
|
|
|
</para> |
|
|
|
|
|
|
|
|
|
<para> |
|
|
|
|
Example: |
|
|
|
|
<screen><![CDATA[ |
|
|
|
|
SELECT xpath_exists('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>', |
|
|
|
|
ARRAY[ARRAY['my', 'http://example.com']]); |
|
|
|
|
|
|
|
|
|
xpath_exists |
|
|
|
|
-------------- |
|
|
|
|
t |
|
|
|
|
(1 row) |
|
|
|
|
]]></screen> |
|
|
|
|
</para> |
|
|
|
|
</sect2> |
|
|
|
|