佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > PostgreSQL中的XML操作函數(shù)代碼

PostgreSQL中的XML操作函數(shù)代碼

熱門標(biāo)簽:呼叫中心市場需求 Linux服務(wù)器 百度競價(jià)排名 鐵路電話系統(tǒng) AI電銷 網(wǎng)站排名優(yōu)化 服務(wù)外包 地方門戶網(wǎng)站

XML內(nèi)容生成部分
SQL數(shù)據(jù)生成XML的函數(shù)。
1. xmlcomment:生成注釋函數(shù)。
xmlcomment(text )
例:

SELECT xmlcomment('hello');
xmlcomment
--------------
!--hello-->

2. xmlconcat:XML連接函數(shù)
xmlconcat(xml [, ...])
例:
SELECT xmlconcat('abc/>', 'bar>foo/bar>');

xmlconcat
----------------------
abc/>bar>foo/bar>

連接的XML數(shù)據(jù)中如果有多個(gè)版本聲明的話,連接后的XML只有一個(gè)版本聲明。
例:
SELECT xmlconcat('?xml version="1.1"?>foo/>', '?xml version="1.1" standalone="no"?>bar/>');

xmlconcat
-----------------------------------
?xml version="1.1"?>foo/>bar/>

3. xmlelement:生成XML元素函數(shù)
xmlelement(name name [, xmlattributes( value [AS attname ] [, ... ])] [ , content, ... ])
例:
SELECT xmlelement(name foo);
xmlelement
------------
foo/>

SELECT xmlelement(name foo, xmlattributes('xyz' as bar));
xmlelement
------------------
foo bar="xyz"/>

SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent');
xmlelement
-------------------------------------
foo bar="2007-01-26">content/foo>

如果有非法字符的話,非常字符會(huì)用 16進(jìn)制的數(shù)字表示出來。
例子:SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "ab"));
xmlelement
----------------------------------
foo_x0024_bar a_x0026_b="xyz"/>

4. xmlforest:生成XML FOREST函數(shù)
xmlforest(content [AS name ] [, ...])
例:
SELECT xmlforest('abc' AS foo, 123 AS bar);
xmlforest
------------------------------
foo>abc/foo>bar>123/bar>

SELECT xmlforest(table_name, column_name)
FROM information_schema.columns
WHERE table_schema = 'pg_catalog';
xmlforest
-------------------------------------------------------------------------------------------
table_name>pg_authid/table_name>column_name>rolname/column_name>
table_name>pg_authid/table_name>column_name>rolsuper/column_name>
...
5. xmlpi:生成XML處理命令函數(shù)。
xmlpi(name target [, content ])
例:
SELECT xmlpi(name php, 'echo "hello world";');
xmlpi
-----------------------------
?php echo "hello world";?>

6. xmlroot:修改XML值的根節(jié)點(diǎn)屬性函數(shù)
xmlroot(xml , version text |no value [, standalone yes|no|no value])
例子:SELECT xmlroot(xmlparse(document '?xml version="1.1"?>content>abc/content>'),
version '1.0', standalone yes);
xmlroot
----------------------------------------
?xml version="1.0" standalone="yes"?>
content>abc/content>

7. xmlagg:xmlagg是集約函數(shù)
xmlagg(xml )
例:
CREATE TABLE test (y int, x xml);
INSERT INTO test VALUES (1, 'foo>abc/foo>');
INSERT INTO test VALUES (2, 'bar/>');
SELECT xmlagg(x) FROM test;
xmlagg
----------------------
foo>abc/foo>bar/>

可以用下面類型的方法改變連接順序。
SELECT xmlagg(x) FROM (SELECT * FROM test ORDER BY y DESC) AS tab;
xmlagg
----------------------
bar/>foo>abc/foo>

Processing XML
為了處理XML數(shù)據(jù),PostgreSL中提供了xpath函數(shù)。
xpath(xpath , xml [, nsarray ])

例:
SELECT xpath('/my:a/text()', 'my:a xmlns:my="http://example.com">test/my:a>',
ARRAY[ARRAY['my', 'http://example.com']]);
xpath
--------
{test}
(1 row)

XML和table的映射
以下函數(shù)可以導(dǎo)出XML。
table_to_xml(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xml(cursor refcursor, count int, nulls boolean,
tableforest boolean, targetns text)
這些函數(shù)的返回值都是XML類型。

還有以下函數(shù)。具體內(nèi)容可以參看用戶手冊。
table_to_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
cursor_to_xmlschema(cursor refcursor, nulls boolean, tableforest boolean, targetns text)
table_to_xml_and_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)
query_to_xml_and_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)
schema_to_xml(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
schema_to_xml_and_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)
database_to_xml(nulls boolean, tableforest boolean, targetns text)
database_to_xmlschema(nulls boolean, tableforest boolean, targetns text)
database_to_xml_and_xmlschema(nulls boolean, tableforest boolean, targetns text)

您可能感興趣的文章:
  • PostgreSQL 正則表達(dá)式 常用函數(shù)的總結(jié)
  • 深入解讀PostgreSQL中的序列及其相關(guān)函數(shù)的用法
  • PostgreSQL教程(七):函數(shù)和操作符詳解(3)
  • PostgreSQL教程(十九):SQL語言函數(shù)
  • PostgreSQL教程(五):函數(shù)和操作符詳解(1)
  • PostgreSQL教程(六):函數(shù)和操作符詳解(2)
  • PostgreSQL Node.js實(shí)現(xiàn)函數(shù)計(jì)算方法示例
  • PostgreSQL數(shù)據(jù)庫中窗口函數(shù)的語法與使用

標(biāo)簽:黃山 湖南 仙桃 衡水 銅川 湘潭 崇左 蘭州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PostgreSQL中的XML操作函數(shù)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    安国市| 普兰县| 惠安县| 和林格尔县| 秦皇岛市| 灯塔市| 淮北市| 唐海县| 衡水市| 定陶县| 临汾市| 衡东县| 九龙县| 墨玉县| 新余市| 宝兴县| 商丘市| 佛坪县| 仪陇县| 武城县| 泰和县| 云阳县| 新和县| 宜良县| 宜川县| 横山县| 襄城县| 平远县| 肥东县| 钟山县| 来宾市| 新源县| 德州市| 鄂尔多斯市| 长治县| 沾益县| 广灵县| 广水市| 阳春市| 若羌县| 儋州市|