1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.524 2010/08/05 18:21:17 tgl Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.525 2010/08/08 19:15:27 tgl Exp $ -->
2
2
3
3
<chapter id="functions">
4
4
<title>Functions and Operators</title>
@@ -8175,7 +8175,7 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
8175
8175
linkend="datatype-xml"> for information about the <type>xml</type>
8176
8176
type. The function-like expressions <function>xmlparse</function>
8177
8177
and <function>xmlserialize</function> for converting to and from
8178
- type <type>xml</type> are not repeated here. Use of many of these
8178
+ type <type>xml</type> are not repeated here. Use of most of these
8179
8179
functions requires the installation to have been built
8180
8180
with <command>configure --with-libxml</>.
8181
8181
</para>
@@ -8231,7 +8231,7 @@ SELECT xmlcomment('hello');
8231
8231
<synopsis>
8232
8232
<function>xmlconcat</function>(<replaceable>xml</replaceable><optional>, ...</optional>)
8233
8233
</synopsis>
8234
-
8234
+
8235
8235
<para>
8236
8236
The function <function>xmlconcat</function> concatenates a list
8237
8237
of individual XML values to create a single value containing an
@@ -8277,18 +8277,18 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', '<?xml version="1.1" standalone=
8277
8277
]]></screen>
8278
8278
</para>
8279
8279
</sect3>
8280
-
8280
+
8281
8281
<sect3>
8282
8282
<title><literal>xmlelement</literal></title>
8283
-
8283
+
8284
8284
<indexterm>
8285
8285
<primary>xmlelement</primary>
8286
8286
</indexterm>
8287
-
8287
+
8288
8288
<synopsis>
8289
8289
<function>xmlelement</function>(name <replaceable>name</replaceable> <optional>, xmlattributes(<replaceable>value</replaceable> <optional>AS <replaceable>attname</replaceable></optional> <optional>, ... </optional>)</optional> <optional><replaceable>, content, ...</replaceable></optional>)
8290
8290
</synopsis>
8291
-
8291
+
8292
8292
<para>
8293
8293
The <function>xmlelement</function> expression produces an XML
8294
8294
element with the given name, attributes, and content.
@@ -8375,18 +8375,18 @@ SELECT xmlelement(name foo, xmlattributes('xyz' as bar),
8375
8375
at which point a more precise description will appear.
8376
8376
</para>
8377
8377
</sect3>
8378
-
8378
+
8379
8379
<sect3>
8380
8380
<title><literal>xmlforest</literal></title>
8381
-
8381
+
8382
8382
<indexterm>
8383
8383
<primary>xmlforest</primary>
8384
8384
</indexterm>
8385
-
8385
+
8386
8386
<synopsis>
8387
8387
<function>xmlforest</function>(<replaceable>content</replaceable> <optional>AS <replaceable>name</replaceable></optional> <optional>, ...</optional>)
8388
8388
</synopsis>
8389
-
8389
+
8390
8390
<para>
8391
8391
The <function>xmlforest</function> expression produces an XML
8392
8392
forest (sequence) of elements using the given names and content.
@@ -8432,18 +8432,18 @@ WHERE table_schema = 'pg_catalog';
8432
8432
<function>xmlelement</function>.
8433
8433
</para>
8434
8434
</sect3>
8435
-
8435
+
8436
8436
<sect3>
8437
8437
<title><literal>xmlpi</literal></title>
8438
-
8438
+
8439
8439
<indexterm>
8440
8440
<primary>xmlpi</primary>
8441
8441
</indexterm>
8442
-
8442
+
8443
8443
<synopsis>
8444
8444
<function>xmlpi</function>(name <replaceable>target</replaceable> <optional>, <replaceable>content</replaceable></optional>)
8445
8445
</synopsis>
8446
-
8446
+
8447
8447
<para>
8448
8448
The <function>xmlpi</function> expression creates an XML
8449
8449
processing instruction. The content, if present, must not
@@ -8461,18 +8461,18 @@ SELECT xmlpi(name php, 'echo "hello world";');
8461
8461
]]></screen>
8462
8462
</para>
8463
8463
</sect3>
8464
-
8464
+
8465
8465
<sect3>
8466
8466
<title><literal>xmlroot</literal></title>
8467
-
8467
+
8468
8468
<indexterm>
8469
8469
<primary>xmlroot</primary>
8470
8470
</indexterm>
8471
-
8471
+
8472
8472
<synopsis>
8473
8473
<function>xmlroot</function>(<replaceable>xml</replaceable>, version <replaceable>text</replaceable> | no value <optional>, standalone yes|no|no value</optional>)
8474
8474
</synopsis>
8475
-
8475
+
8476
8476
<para>
8477
8477
The <function>xmlroot</function> expression alters the properties
8478
8478
of the root node of an XML value. If a version is specified,
@@ -8483,7 +8483,7 @@ SELECT xmlpi(name php, 'echo "hello world";');
8483
8483
8484
8484
<para>
8485
8485
<screen><![CDATA[
8486
- SELECT xmlroot(xmlparse(document '<?xml version="1.1"?><content>abc</content>'),
8486
+ SELECT xmlroot(xmlparse(document '<?xml version="1.1"?><content>abc</content>'),
8487
8487
version '1.0', standalone yes);
8488
8488
8489
8489
xmlroot
@@ -8636,17 +8636,19 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor
8636
8636
8637
8637
<para>
8638
8638
To process values of data type <type>xml</type>, PostgreSQL offers
8639
- the function <function>xpath</function>, which evaluates XPath 1.0
8639
+ the functions <function>xpath</function> and
8640
+ <function>xpath_exists</function>, which evaluate XPath 1.0
8640
8641
expressions.
8641
8642
</para>
8642
8643
8643
8644
<synopsis>
8644
- <function>xpath</function>(<replaceable>xpath</replaceable>, <replaceable>xml</replaceable><optional>, <replaceable>nsarray</replaceable></optional>)
8645
+ <function>xpath</function>(<replaceable>xpath</replaceable>, <replaceable>xml</replaceable> <optional>, <replaceable>nsarray</replaceable></optional>)
8645
8646
</synopsis>
8646
8647
8647
8648
<para>
8648
8649
The function <function>xpath</function> evaluates the XPath
8649
- expression <replaceable>xpath</replaceable> against the XML value
8650
+ expression <replaceable>xpath</replaceable> (a <type>text</> value)
8651
+ against the XML value
8650
8652
<replaceable>xml</replaceable>. It returns an array of XML values
8651
8653
corresponding to the node set produced by the XPath expression.
8652
8654
</para>
@@ -8657,21 +8659,21 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor
8657
8659
</para>
8658
8660
8659
8661
<para>
8660
- The third argument of the function is an array of namespace
8661
- mappings. This array should be a two-dimensional array with the
8662
- length of the second axis being equal to 2 (i.e., it should be an
8662
+ The optional third argument of the function is an array of namespace
8663
+ mappings. This array should be a two-dimensional <type>text</> array with
8664
+ the length of the second axis being equal to 2 (i.e., it should be an
8663
8665
array of arrays, each of which consists of exactly 2 elements).
8664
8666
The first element of each array entry is the namespace name (alias), the
8665
8667
second the namespace URI. It is not required that aliases provided in
8666
- this array are the same that those being used in the XML document itself (in
8668
+ this array be the same as those being used in the XML document itself (in
8667
8669
other words, both in the XML document and in the <function>xpath</function>
8668
8670
function context, aliases are <emphasis>local</>).
8669
8671
</para>
8670
8672
8671
8673
<para>
8672
8674
Example:
8673
8675
<screen><![CDATA[
8674
- SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
8676
+ SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
8675
8677
ARRAY[ARRAY['my', 'http://example.com']]);
8676
8678
8677
8679
xpath
@@ -8682,7 +8684,7 @@ SELECT xpath('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
8682
8684
</para>
8683
8685
8684
8686
<para>
8685
- How to deal with default (anonymous) namespaces:
8687
+ To deal with default (anonymous) namespaces, do something like this :
8686
8688
<screen><![CDATA[
8687
8689
SELECT xpath('//mydefns:b/text()', '<a xmlns="http://example.com"><b>test</b></a>',
8688
8690
ARRAY[ARRAY['mydefns', 'http://example.com']]);
@@ -8691,14 +8693,44 @@ SELECT xpath('//mydefns:b/text()', '<a xmlns="http://example.com"><b>test</b></a
8691
8693
--------
8692
8694
{test}
8693
8695
(1 row)
8696
+ ]]></screen>
8697
+ </para>
8698
+
8699
+ <indexterm>
8700
+ <primary>xpath_exists</primary>
8701
+ </indexterm>
8702
+
8703
+ <synopsis>
8704
+ <function>xpath_exists</function>(<replaceable>xpath</replaceable>, <replaceable>xml</replaceable> <optional>, <replaceable>nsarray</replaceable></optional>)
8705
+ </synopsis>
8706
+
8707
+ <para>
8708
+ The function <function>xpath_exists</function> is a specialized form
8709
+ of the <function>xpath</function> function. Instead of returning the
8710
+ individual XML values that satisfy the XPath, this function returns a
8711
+ boolean indicating whether the query was satisfied or not. This
8712
+ function is equivalent to the standard <literal>XMLEXISTS</> predicate,
8713
+ except that it also offers support for a namespace mapping argument.
8714
+ </para>
8715
+
8716
+ <para>
8717
+ Example:
8718
+ <screen><![CDATA[
8719
+ SELECT xpath_exists('/my:a/text()', '<my:a xmlns:my="http://example.com">test</my:a>',
8720
+ ARRAY[ARRAY['my', 'http://example.com']]);
8721
+
8722
+ xpath_exists
8723
+ --------------
8724
+ t
8725
+ (1 row)
8694
8726
]]></screen>
8695
8727
</para>
8696
8728
</sect2>
8697
8729
8698
8730
<sect2 id="functions-xml-mapping">
8699
8731
<title>Mapping Tables to XML</title>
8700
8732
8701
- <indexterm zone="functions-xml-mapping">
8733
+ <indexterm zone="functions-xml-mapping">
8702
8734
<primary>XML export</primary>
8703
8735
</indexterm>
8704
8736
0 commit comments