mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add xml_is_well_formed, xml_is_well_formed_document, xml_is_well_formed_content
functions to the core XML code. Per discussion, the former depends on XMLOPTION while the others do not. These supersede a version previously offered by contrib/xml2. Mike Fowler, reviewed by Pavel Stehule
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.526 2010/08/10 21:51:00 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.527 2010/08/13 18:36:23 tgl Exp $ -->
|
||||
|
||||
<chapter id="functions">
|
||||
<title>Functions and Operators</title>
|
||||
@ -8625,6 +8625,84 @@ SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Tor
|
||||
supports XPath, which is a subset of XQuery.
|
||||
</para>
|
||||
</sect3>
|
||||
|
||||
<sect3>
|
||||
<title>xml_is_well_formed</title>
|
||||
|
||||
<indexterm>
|
||||
<primary>xml_is_well_formed</primary>
|
||||
</indexterm>
|
||||
|
||||
<indexterm>
|
||||
<primary>xml_is_well_formed_document</primary>
|
||||
</indexterm>
|
||||
|
||||
<indexterm>
|
||||
<primary>xml_is_well_formed_content</primary>
|
||||
</indexterm>
|
||||
|
||||
<synopsis>
|
||||
<function>xml_is_well_formed</function>(<replaceable>text</replaceable>)
|
||||
<function>xml_is_well_formed_document</function>(<replaceable>text</replaceable>)
|
||||
<function>xml_is_well_formed_content</function>(<replaceable>text</replaceable>)
|
||||
</synopsis>
|
||||
|
||||
<para>
|
||||
These functions check whether a <type>text</> string is well-formed XML,
|
||||
returning a boolean result.
|
||||
<function>xml_is_well_formed_document</function> checks for a well-formed
|
||||
document, while <function>xml_is_well_formed_content</function> checks
|
||||
for well-formed content. <function>xml_is_well_formed</function> does
|
||||
the former if the <xref linkend="guc-xmloption"> configuration
|
||||
parameter is set to <literal>DOCUMENT</>, or the latter if it is set to
|
||||
<literal>CONTENT</>. This means that
|
||||
<function>xml_is_well_formed</function> is useful for seeing whether
|
||||
a simple cast to type <type>xml</> will succeed, whereas the other two
|
||||
functions are useful for seeing whether the corresponding variants of
|
||||
<function>XMLPARSE</> will succeed.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Examples:
|
||||
|
||||
<screen><![CDATA[
|
||||
SET xmloption TO DOCUMENT;
|
||||
SELECT xml_is_well_formed('<>');
|
||||
xml_is_well_formed
|
||||
--------------------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SELECT xml_is_well_formed('<abc/>');
|
||||
xml_is_well_formed
|
||||
--------------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SET xmloption TO CONTENT;
|
||||
SELECT xml_is_well_formed('abc');
|
||||
xml_is_well_formed
|
||||
--------------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT xml_is_well_formed_document('<pg:foo xmlns:pg="http://postgresql.org/stuff">bar</pg:foo>');
|
||||
xml_is_well_formed_document
|
||||
-----------------------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT xml_is_well_formed_document('<pg:foo xmlns:pg="http://postgresql.org/stuff">bar</my:foo>');
|
||||
xml_is_well_formed_document
|
||||
-----------------------------
|
||||
f
|
||||
(1 row)
|
||||
]]></screen>
|
||||
|
||||
The last example shows that the checks include whether
|
||||
namespaces are correctly matched.
|
||||
</para>
|
||||
</sect3>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="functions-xml-processing">
|
||||
|
Reference in New Issue
Block a user