xmlconcat()

A function for concatenating XML strings

xmlconcat() is a system function for concatenating XML snippets into a single XML content fragment.

xmlconcat() was added in PostgreSQL 8.3.

Usage

xmlconcat ( xml [, ...] ) → xml

NULL values will be omitted; XML declarations. if present, will be consolidated into a single declaration if feasible (see the documentation for details); any encoding declarations will be removed.

Change history

Examples

Basic usage example for xmlconcat():

postgres=# SELECT xmlconcat('<bar>foo</bar>','<baz>boo</baz>', '<moo/>');
             xmlconcat              
------------------------------------
 <bar>foo</bar><baz>boo</baz><moo/>
(1 row)

NULL elements and empty strings will be ignored:

postgres=# SELECT xmlconcat('<bar>foo</bar>',NULL,'','<moo/>');
      xmlconcat
----------------------
 <bar>foo</bar><moo/>
(1 row)

unless all input elements are NULL:

postgres=# SELECT xmlconcat(NULL,NULL) IS NULL;
 ?column? 
----------
 t
(1 row)

Plain text strings will simply be concatenated:

postgres=# SELECT xmlconcat('foo','bar');
 xmlconcat 
-----------
 foobar
(1 row)

Otherwise each input element must be well-formed XML:

postgres=# SELECT xmlconcat('<foo>bar', '</foo>');
ERROR:  invalid XML content
LINE 1: SELECT xmlconcat('<foo>bar', '</foo>');
                         ^
DETAIL:  line 1: Premature end of data in tag foo line 1
<foo>bar

Encoding declarations will be stripped:

postgres=# SELECT xmlconcat('<?xml version="1.1" encoding="iso-8859-1"?>',
                            '<?xml version="1.1"?><foo>Äthiopien</foo>');
                 xmlconcat
-------------------------------------------
 <?xml version="1.1"?><foo>Äthiopien</foo>
(1 row)

Categories

System function, XML