网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体 EIHealth
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务
本文导读

展开导读

XML类型函数

更新时间:2024-07-03 GMT+08:00
分享
  • xmlparse ( { DOCUMENT | CONTENT } value [wellformed])

    描述:使用函数xmlparse,从字符数据产生XML类型的值。

    参数:数据类型为text。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    gaussdb=# SELECT XMLPARSE (DOCUMENT '<?xml version="1.0"?><book><title>Manual</title><chapter>...</chapter></book>');
                          xmlparse                         
    ----------------------------------------------------------
     <book><title>Manual</title><chapter>...</chapter></book>
    (1 row)
    gaussdb=# SELECT XMLPARSE (CONTENT 'abc<foo>bar</foo><bar>foo</bar>');
              xmlparse             
    ---------------------------------
     abc<foo>bar</foo><bar>foo</bar>
    (1 row)
    gaussdb=# SELECT XMLPARSE (CONTENT 'abc<foo>bar</foo' wellformed);
         xmlparse
    ------------------
     abc<foo>bar</foo
    (1 row)
    
  • xmlserialize( { DOCUMENT | CONTENT } value AS type )

    描述:使用函数xmlserialize,从xml产生一个字符串。

    参数:类型可以是character,character varying或text(或其中某个的变种)。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    gaussdb=# SELECT XMLSERIALIZE(CONTENT 'good' AS CHAR(10));
     xmlserialize 
    --------------
     good
    (1 row)
    gaussdb=# SELECT xmlserialize(DOCUMENT '<head>bad</head>' as text);
       xmlserialize   
    ------------------
     <head>bad</head>
    (1 row)
    
    说明:
    当一个字符串值在没有通过XMLPARSE或XMLSERIALIZE的情况下,与XML类型进行转换时,具体选择DOCUMENT或CONTENT由“XML option”会话配置参数决定,这个配置参数可以由标准命令来设置:
    1
    SET XML OPTION { DOCUMENT | CONTENT };
    

    或使用类似的语法来设置:

    1
    SET xmloption TO { DOCUMENT | CONTENT };
    
  • xmlcomment(text)

    描述:创建一个XML值,并且它包含一个用指定文本作为内容的XML注释。该文本不包含“--”字符且结尾不存在“-”字符、符合XML注释的格式要求。且当参数为空时、结果也为空。

    参数:数据类型为text。

    返回值类型:XML

    示例:

    1
    2
    3
    4
    gaussdb=# SELECT xmlcomment('hello');
      xmlcomment
    --------------
     <!--hello-->
    
  • xmlconcat(xml[, ...])

    描述:将由单个XML值组成的列表串接成一个单独的值,该值包含一个XML的内容片段。其中空值会被忽略,并且只有当所有参数都为空时结果才为空。在兼容ORA数据库模式下,设置a_format_version值为10c和a_format_dev_version值为s2,增加了校验输入片段是否为非良构xml文本。

    参数:数据类型为XML。

    返回值类型:XML

    示例1:

    gaussdb=# SET xmloption=content;
    SET
    gaussdb=# SELECT XMLCONCAT(('<?xml version="1.0" encoding="GB2312" standalone="no"?><bar>foo</bar>'),('<?xml version="1.0" encoding="GB2312" standalone="no" ?><bar>foo</bar>')) ;
                                 xmlconcat
    -------------------------------------------------------------------
    <?xml version="1.0" standalone="no"?><bar>foo</bar><bar>foo</bar>
    (1 row)
    gaussdb=# SELECT XMLCONCAT('abc>');
     xmlconcat
    -----------
     abc>
    (1 row)
    

    示例2:兼容ORA数据库的语法示例。

    gaussdb=# CREATE DATABASE gaussdb_ora DBCOMPATIBILITY='ORA';
    CREATE DATABASE
    gaussdb=# \c gaussdb_ora
    gaussdb_ora=# SET a_format_version='10c';
    SET
    gaussdb_ora=# SET a_format_dev_version=s2;
    SET
    gaussdb_ora=# SET xmloption=content;
    SET
    gaussdb_ora=# SELECT XMLCONCAT(('<?xml version="1.0" encoding="GB2312" standalone="no"?><bar>foo</bar>'),('<?xml version="1.0" encoding="GB2312" standalone="no" ?><bar>foo</bar>')) ;
                                 xmlconcat
    -------------------------------------------------------------------
     <?xml version="1.0" standalone="no"?><bar>foo</bar><bar>foo</bar>
    (1 row)
    
    gaussdb_ora=# SELECT XMLCONCAT('abc>');
    ERROR:  invalid XML document
    DETAIL:  line 1: Start tag expected, '<' not found
    abc>
    ^
    CONTEXT:  referenced column: xmlconcat
    gaussdb_ora=# \c postgres
    gaussdb=# DROP DATABASE gaussdb_ora;
    DROP DATABASE
  • xmlagg(xml [order_by_clause])

    描述:该函数是一个聚集函数、它将聚集函数调用的输入值串接起来,且支持跨行串接,order_by_clause详见SELECT。在兼容ORA数据库模式下,设置a_format_version值为10c和a_format_dev_version值为s2,数据库xmloption参数默认为content,当xmloption设置为document时,使用换行符串接多行XML。若XML声明中encoding属性值不为默认编码UTF-8时,聚集结果有XML声明。

    参数:XML

    返回值类型:XML

    示例1:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    gaussdb=# CREATE TABLE xmltest (
                id int,
                data xml
               );
    NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using 'id' as the distribution column by default.
    HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
    gaussdb=# INSERT INTO xmltest VALUES (1, '<value>one</value>');
    INSERT 0 1
    gaussdb=# INSERT INTO xmltest VALUES (2, '<value>two</value>');
    INSERT 0 1
    gaussdb=# SELECT xmlagg(data) FROM xmltest;
                    xmlagg                
    --------------------------------------
     <value>one</value><value>two</value>
    (1 row)
    

    示例2:兼容ORA数据库的语法示例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    gaussdb=# SET xmloption=document;
    SET
    gaussdb=# SELECT xmlagg(data) FROM xmltest;
           xmlagg       
    --------------------
     <value>one</value>+
     <value>two</value>
    (1 row)
    gaussdb=# DELETE FROM XMLTEST;
    DELETE 2
    gaussdb=# INSERT INTO xmltest VALUES (1, '<?xml version="1.0" encoding="GBK"?><value>one</value>');
    INSERT 0 1
    gaussdb=# INSERT INTO xmltest VALUES (2, '<?xml version="1.0" encoding="GBK"?><value>two</value>');
    INSERT 0 1
    gaussdb=# SELECT xmlagg(data) FROM xmltest;
                             xmlagg                         
    --------------------------------------------------------
     <?xml version="1.0" encoding="GBK"?><value>one</value>+
     <value>two</value>
    (1 row)
    gaussdb=# SELECT xmlagg(data order by id desc) FROM xmltest;
                             xmlagg                         
    --------------------------------------------------------
     <?xml version="1.0" encoding="GBK"?><value>two</value>+
     <value>one</value>
    (1 row)
    
    gaussdb=# DROP TABLE xmltest;
    
  • xmlelement( [ ENTITYESCAPING | NOENTITYESCAPING ] { [ NAME ] element_name | EVALNAME element_name } [ , xmlattributes( [ ENTITYESCAPING | NOENTITYESCAPING ] value [ [ AS ] attname | AS EVALNAME attname ] [ , ... ] ) ] [ , content [ [ AS ] alias ] [ , ... ] ] )

    描述:使用给定的名称、属性和内容产生一个XML元素。

    返回值类型:XML

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    gaussdb=# SELECT xmlelement(name foo);
     xmlelement
    ------------
     <foo/>
    
    --在ORA兼容模式下。
    gaussdb=# CREATE DATABASE gaussdb_ora DBCOMPATIBILITY='ORA';
    CREATE DATABASE
    gaussdb=# \c gaussdb_ora
    gaussdb_ora=# SET a_format_version='10c';
    SET
    gaussdb_ora=# SET a_format_dev_version=s2;
    SET
    --xmlelement中默认不设置或者设置ENTITYESCAPING关键字时,xmlelement的内容中的保留字符将被转义。
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", 'a$><&"b');
                             xmlelement                          
    -------------------------------------------------------------
     <entityescaping<>>a$&gt;&lt;&amp;&quot;b</entityescaping<>>
    (1 row)
    
    gaussdb_ora=# SELECT xmlelement(entityescaping "entityescaping<>", 'a$><&"b');
                             xmlelement                          
    -------------------------------------------------------------
     <entityescaping<>>a$&gt;&lt;&amp;&quot;b</entityescaping<>>
    (1 row)
    
    --xmlelement中设置NOENTITYESCAPING关键字时,xmlelement的内容中的保留字符将不会被转义。
    gaussdb_ora=# SELECT xmlelement(noentityescaping "entityescaping<>", 'a$><&"b');
                      xmlelement                  
    ----------------------------------------------
     <entityescaping<>>a$><&"b</entityescaping<>>
    (1 row)
    
    --xmlelement中对内容使用[as] alias声明别名时,内容值类型必须为xml类型。
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", '<abc/>' b);
    ERROR:  argument of XMLELEMENT must be type xml, not type unknown
    LINE 1: SELECT xmlelement("entityescaping<>", '<abc/>' b);
                                                  ^
    CONTEXT:  referenced column: xmlelement
    
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", '<abc/>' as b);
    ERROR:  argument of XMLELEMENT must be type xml, not type unknown
    LINE 1: SELECT xmlelement("entityescaping<>", '<abc/>' as b);
                                                  ^
    CONTEXT:  referenced column: xmlelement
    
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", xml('<abc/>') b);
                     xmlelement                  
    ---------------------------------------------
     <entityescaping<>><abc/></entityescaping<>>
    (1 row)
    
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", xml('<abc/>') as b);
                     xmlelement                  
    ---------------------------------------------
     <entityescaping<>><abc/></entityescaping<>>
    (1 row)
    
    --xmlattributes中默认不设置或者设置ENTITYESCAPING关键字时,xmlattributes的内容中的保留字符将被转义。
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", xmlattributes('entityescaping<>' "entityescaping<>"));
                              xmlelement                           
    ---------------------------------------------------------------
     <entityescaping<> entityescaping<>="entityescaping&lt;&gt;"/>
    (1 row)
    
    gaussdb_ora=# SELECT xmlelement(name "entityescaping<>", xmlattributes(entityescaping 'entityescaping<>' "entityescaping<>"));
                              xmlelement                           
    ---------------------------------------------------------------
     <entityescaping<> entityescaping<>="entityescaping&lt;&gt;"/>
    (1 row)
    
    --xmlattributes中设置NOENTITYESCAPING关键字时,xmlattributes的内容中的保留字符将不会被转义。
    gaussdb_ora=# SELECT xmlelement("entityescaping<>", xmlattributes(noentityescaping 'entityescaping<>' "entityescaping<>"));
                           xmlelement                        
    ---------------------------------------------------------
     <entityescaping<> entityescaping<>="entityescaping<>"/>
    (1 row)
    
    gaussdb_ora=# \c postgres
    gaussdb=# DROP DATABASE gaussdb_ora;
    DROP DATABASE
    
    说明:
    1. xmlelement和xmlattributes的name字段赋NULL时,行为与O不一致。xmlelement的name字段赋NULL时,结果显示name信息为空,且不显示属性信息。xmlattributes的name字段赋NULL时,不显示属性信息。
    2. 设置如下两个参数后,xmlelement的内容转义规则为ORA兼容,未设置时xmlelement的内容转义规则为PG兼容。
      1
      2
      SET a_format_version='10c';
      SET a_format_dev_version=s2;
      
  • xmlforest(content [AS name] [, ...])

    描述:使用给定名称和内容产生一个元素的XML序列。

    返回值类型:XML

    示例:
    1
    2
    3
    4
    gaussdb=# SELECT xmlforest('abc' AS foo, 123 AS bar);
              xmlforest
    ------------------------------
     <foo>abc</foo><bar>123</bar>
    
  • xmlpi(name target [, content])

    描述:创建一个XML处理指令。若内容不为空,则内容不能包含字符序列。

    返回值类型:XML

    示例:
    1
    2
    3
    4
    gaussdb=# SELECT xmlpi(name php, 'echo "hello world";');
                xmlpi
    -----------------------------
     <?php echo "hello world";?>
    
  • xmlroot(xml, version text | no value [, standalone yes|no|no value])

    描述:修改一个XML值的根节点的属性。如果指定了一个版本,它会替换根节点的版本声明中的值,如果指定了一个独立设置,它会替换根节点的独立声明中的值。

    示例:
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmlroot('<?xml version="1.1"?><content>abc</content>',version '1.0', standalone yes);
                               xmlroot
    --------------------------------------------------------------
     <?xml version="1.0" standalone="yes"?><content>abc</content>
    (1 row)
    
  • xmlexists(text passing [BY REF] xml [BY REF])

    描述:评价一个XPath 1.0表达式(第一个参数),以传递的XML值作为其上下文项。 如果评价的结果产生一个空节点集,该函数返回false,如果产生任何其他值,则返回true。 如果任何参数为空,则函数返回null。 作为上下文项传递的非空值必须是一个XML文档,而不是内容片段或任何非XML值。

    参数:XML

    返回值类型:BOOLEAN

    示例:
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmlexists('//town[text() = ''Toronto'']' PASSING BY REF '<towns><town>Toronto</town><town>Ottawa</town></towns>');
     xmlexists
    ------------
     t
    (1 row)
    
  • xml_is_well_formed(text)

    描述:检查text是不是正确的XML类型格式、返回值为布尔类型。

    参数:text。

    返回值类型:BOOLEAN

    示例:
    1
    2
    3
    4
    5
    gaussdb=# SELECT xml_is_well_formed('<>');
     xml_is_well_formed 
    --------------------
     f
    (1 row)
    
  • xml_is_well_formed_document(text)

    描述:检查text是不是正确的XML类型格式、返回值为布尔类型。

    参数:text

    返回值类型:BOOLEAN

    示例:
    1
    2
    3
    4
    5
    gaussdb=# 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)
    
  • xml_is_well_formed_content(text)

    描述:检查text是不是正确的XML类型格式、返回值为布尔类型。

    参数:text

    返回值类型:BOOLEAN

    示例:
    1
    2
    3
    4
    5
    gaussdb=# SELECT xml_is_well_formed_content('k');
     xml_is_well_formed_content
    ----------------------------
     t
    (1 row)
    
  • xpath(xpath, xml [, nsarray])

    描述:在XML类型的数据xml上计算XPath 1.0表达式如:xpath (a text value)。它返回一个XML值的数组,该数组对应于该XPath表达式产生的节点集合。如果该XPath表达式返回一个标量值而不是一个节点集合,将会返回一个单一元素的数组。

    第二个参数必须是一个良构的XML文档。注意,它必须有一个单一根节点元素。

    该函数可选的第三个参数是一个名字空间映射的数组。这个数组应该是一个二维text数组,其第二轴长度等于2(即它应该是一个数组的数组,其中每一个都刚好由2个元素组成)。每个数组项的第一个元素是名字空间的名称(别名),第二个元素是名字空间的URI。并不要求在这个数组中提供的别名和在XML文档本身中使用的那些名字空间相同(即在XML文档中和在xpath函数环境中,别名都是本地的)。

    返回值类型:XML

    示例:
    1
    2
    3
    4
    5
    gaussdb=# 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)
    
  • xpath_exists(xpath, xml [, nsarray])

    描述:该函数是xpath函数的一种特殊形式。这个函数不是返回满足XPath 1.0表达式的单一XML值,它返回一个布尔值表示查询是否被满足(它是否产生了空节点集以外的任何值)。这个函数等价于标准的XMLEXISTS谓词,不过它还提供了对一个名字空间映射参数的支持。

    返回值类型:BOOLEAN

    示例:
    1
    2
    3
    4
    5
    gaussdb=# 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)
    
说明:
以下XML类型函数示例中,需进行前置数据准备,如下所示:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
gaussdb=# CREATE SCHEMA testxmlschema;
CREATE SCHEMA
gaussdb=# CREATE TABLE testxmlschema.test1 (a int, b text);
CREATE TABLE
gaussdb=# INSERT INTO testxmlschema.test1 VALUES (1, 'one'), (2, 'two'), (-1, null);
INSERT 0 3
gaussdb=# CREATE DATABASE test;
CREATE DATABASE

--示例执行结束后,可使用如下命令删除上述前置数据。
gaussdb=# DROP DATABASE test;
DROP DATABASE
gaussdb=# DROP TABLE testxmlschema.test1;
DROP TABLE
gaussdb=# DROP SCHEMA testxmlschema;
DROP SCHEMA
  • query_to_xml(query text, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将query查询的内容映射成XML模式文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    gaussdb=# SELECT query_to_xml('SELECT * FROM testxmlschema.test1', false, false, '');
                             query_to_xml                          
    ---------------------------------------------------------------
     <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                  +
     <row>                                                        +
       <a>1</a>                                                   +
       <b>one</b>                                                 +
     </row>                                                       +
                                                                  +
     <row>                                                        +
       <a>2</a>                                                   +
       <b>two</b>                                                 +
     </row>                                                       +
                                                                  +
     <row>                                                        +
       <a>-1</a>                                                  +
     </row>                                                       +
                                                                  +
     </table>                                                     +
    (1 row)
    

  • query_to_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将query查询的内容映射成XML文档和XML模式文档,并把两个文档连接在一起。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    gaussdb=# SELECT query_to_xmlschema('SELECT * FROM testxmlschema.test1', false, false, '');
                                          query_to_xmlschema                                      
    ----------------------------------------------------------------------------------------------
     <xsd:schema                                                                                 +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                           +
                                                                                                 +
     <xsd:simpleType name="INTEGER">                                                             +
       <xsd:restriction base="xsd:int">                                                          +
         <xsd:maxInclusive value="2147483647"/>                                                  +
         <xsd:minInclusive value="-2147483648"/>                                                 +
       </xsd:restriction>                                                                        +
     </xsd:simpleType>                                                                           +
                                                                                                 +
     <xsd:simpleType name="UDT.regression.pg_catalog.text">                                      +
       <xsd:restriction base="xsd:string">                                                       +
       </xsd:restriction>                                                                        +
     </xsd:simpleType>                                                                           +
                                                                                                 +
     <xsd:complexType name="RowType">                                                            +
       <xsd:sequence>                                                                            +
         <xsd:element name="a" type="INTEGER" minOccurs="0"></xsd:element>                       +
         <xsd:element name="b" type="UDT.regression.pg_catalog.text" minOccurs="0"></xsd:element>+
       </xsd:sequence>                                                                           +
     </xsd:complexType>                                                                          +
                                                                                                 +
     <xsd:complexType name="TableType">                                                          +
       <xsd:sequence>                                                                            +
         <xsd:element name="row" type="RowType" minOccurs="0" maxOccurs="unbounded"/>            +
       </xsd:sequence>                                                                           +
     </xsd:complexType>                                                                          +
                                                                                                 +
     <xsd:element name="table" type="TableType"/>                                                +
                                                                                                 +
     </xsd:schema>
    (1 row)
    

  • query_to_xml_and_xmlschema(query text, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将query查询的内容映射成XML文档和XML模式文档,并把两个文档连接在一起。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    gaussdb=# SELECT query_to_xml_and_xmlschema('SELECT * FROM testxmlschema.test1', true, true, '');
                                       query_to_xml_and_xmlschema                                   
    ------------------------------------------------------------------------------------------------
     <xsd:schema                                                                                   +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                             +
                                                                                                   +
     <xsd:simpleType name="INTEGER">                                                               +
       <xsd:restriction base="xsd:int">                                                            +
         <xsd:maxInclusive value="2147483647"/>                                                    +
         <xsd:minInclusive value="-2147483648"/>                                                   +
       </xsd:restriction>                                                                          +
     </xsd:simpleType>                                                                             +
                                                                                                   +
     <xsd:simpleType name="UDT.regression.pg_catalog.text">                                        +
       <xsd:restriction base="xsd:string">                                                         +
       </xsd:restriction>                                                                          +
     </xsd:simpleType>                                                                             +
                                                                                                   +
     <xsd:complexType name="RowType">                                                              +
       <xsd:sequence>                                                                              +
         <xsd:element name="a" type="INTEGER" nillable="true"></xsd:element>                       +
         <xsd:element name="b" type="UDT.regression.pg_catalog.text" nillable="true"></xsd:element>+
       </xsd:sequence>                                                                             +
     </xsd:complexType>                                                                            +
                                                                                                   +
     <xsd:element name="row" type="RowType"/>                                                      +
                                                                                                   +
     </xsd:schema>                                                                                 +
                                                                                                   +
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">                                   +
                                                                                                   +
       <a>1</a>                                                                                    +
       <b>one</b>                                                                                  +
     </row>                                                                                        +
                                                                                                   +
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">                                   +
                                                                                                   +
       <a>2</a>                                                                                    +
       <b>two</b>                                                                                  +
     </row>                                                                                        +
                                                                                                   +
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">                                   +
                                                                                                   +
       <a>-1</a>                                                                                   +
       <b xsi:nil="true"/>                                                                         +
     </row>                                                                                        +
                                                                                                   +
    (1 row)
    

  • cursor_to_xml(cursor refcursor, count int, nulls boolean,tableforest boolean, targetns text)

    描述:该函数会将游标查询的内容映射成XML文档。

    返回值类型:XML

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    gaussdb=#CURSOR xc WITH HOLD FOR SELECT * FROM testxmlschema.test1 ORDER BY 1, 2;
    DECLARE CURSOR
    gaussdb=# SELECT cursor_to_xml('xc'::refcursor, 5, false, true, '');
                            cursor_to_xml                        
    -------------------------------------------------------------
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                +
       <a>-1</a>                                                +
     </row>                                                     +
                                                                +
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                +
       <a>1</a>                                                 +
       <b>one</b>                                               +
     </row>                                                     +
                                                                +
     <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                +
       <a>2</a>                                                 +
       <b>two</b>                                               +
     </row>                                                     +
                                                                +
    
    (1 row)
    

  • cursor_to_xmlschema(cursor refcursor, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将游标查询的内容映射成XML模式文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    gaussdb=# SELECT cursor_to_xmlschema('xc'::refcursor, true, false, '');
                                          cursor_to_xmlschema                                       
    ------------------------------------------------------------------------------------------------
     <xsd:schema                                                                                   +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                             +
                                                                                                   +
     <xsd:simpleType name="INTEGER">                                                               +
       <xsd:restriction base="xsd:int">                                                            +
         <xsd:maxInclusive value="2147483647"/>                                                    +
         <xsd:minInclusive value="-2147483648"/>                                                   +
       </xsd:restriction>                                                                          +
     </xsd:simpleType>                                                                             +
                                                                                                   +
     <xsd:simpleType name="UDT.regression.pg_catalog.text">                                        +
       <xsd:restriction base="xsd:string">                                                         +
       </xsd:restriction>                                                                          +
     </xsd:simpleType>                                                                             +
                                                                                                   +
     <xsd:complexType name="RowType">                                                              +
       <xsd:sequence>                                                                              +
         <xsd:element name="a" type="INTEGER" nillable="true"></xsd:element>                       +
         <xsd:element name="b" type="UDT.regression.pg_catalog.text" nillable="true"></xsd:element>+
       </xsd:sequence>                                                                             +
     </xsd:complexType>                                                                            +
                                                                                                   +
     <xsd:complexType name="TableType">                                                            +
       <xsd:sequence>                                                                              +
         <xsd:element name="row" type="RowType" minOccurs="0" maxOccurs="unbounded"/>              +
       </xsd:sequence>                                                                             +
     </xsd:complexType>                                                                            +
                                                                                                   +
     <xsd:element name="table" type="TableType"/>                                                  +
                                                                                                   +
     </xsd:schema>
    (1 row)
    

  • schema_to_xml(schema name, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个模式的内容映射成XML文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    gaussdb=# SELECT schema_to_xml('testxmlschema', false, true, '');
                                 schema_to_xml                             
    -----------------------------------------------------------------------
     <testxmlschema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                          +
     <test1>                                                              +
                                                                          +
       <a>1</a>                                                           +
       <b>one</b>                                                         +
     </test1>                                                             +
                                                                          +
     <test1>                                                              +
                                                                          +
       <a>2</a>                                                           +
       <b>two</b>                                                         +
     </test1>                                                             +
                                                                          +
     <test1>                                                              +
                                                                          +
       <a>-1</a>                                                          +
     </test1>                                                             +
                                                                          +
                                                                          +
     </testxmlschema>                                                     +
    (1 row)
    

  • schema_to_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个模式的内容映射成XML模式文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    gaussdb=# SELECT schema_to_xmlschema('testxmlschema', false, true, '');
                                                schema_to_xmlschema                                            
    -----------------------------------------------------------------------------------------------------------
     <xsd:schema                                                                                              +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                                        +
                                                                                                              +
     <xsd:simpleType name="INTEGER">                                                                          +
       <xsd:restriction base="xsd:int">                                                                       +
         <xsd:maxInclusive value="2147483647"/>                                                               +
         <xsd:minInclusive value="-2147483648"/>                                                              +
       </xsd:restriction>                                                                                     +
     </xsd:simpleType>                                                                                        +
                                                                                                              +
     <xsd:simpleType name="UDT.t1.pg_catalog.text">                                                           +
       <xsd:restriction base="xsd:string">                                                                    +
       </xsd:restriction>                                                                                     +
     </xsd:simpleType>                                                                                        +
                                                                                                              +
     <xsd:complexType name="SchemaType.t1.testxmlschema">                                                     +
       <xsd:sequence>                                                                                         +
         <xsd:element name="test1" type="RowType.t1.testxmlschema.test1" minOccurs="0" maxOccurs="unbounded"/>+
       </xsd:sequence>                                                                                        +
     </xsd:complexType>                                                                                       +
                                                                                                              +
     <xsd:element name="testxmlschema" type="SchemaType.t1.testxmlschema"/>                                   +
                                                                                                              +
     </xsd:schema>
    (1 row)
    

  • schema_to_xml_and_xmlschema(schema name, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个模式的内容映射成XML文档和XML模式文档,并把两个文档连接在一起。

    返回值类型:XML

    示例:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     gaussdb=# SELECT schema_to_xml_and_xmlschema('testxmlschema', true, true, 'foo');
                                             schema_to_xml_and_xmlschema                                          
    --------------------------------------------------------------------------------------------------------------
     <testxmlschema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="foo" xsi:schemaLocation="foo #">+
                                                                                                                 +
                                                                                         +
     <xsd:schema                                                                                                 +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"                                                            +
         targetNamespace="foo"                                                                                   +
         elementFormDefault="qualified">                                                                         +
                                                                                                                 +
     <xsd:simpleType name="INTEGER">                                                                             +
       <xsd:restriction base="xsd:int">                                                                          +
         <xsd:maxInclusive value="2147483647"/>                                                                  +
         <xsd:minInclusive value="-2147483648"/>                                                                 +
       </xsd:restriction>                                                                                        +
     </xsd:simpleType>                                                                                           +
                                                                                                                 +
     <xsd:simpleType name="UDT.t1.pg_catalog.text">                                                              +
       <xsd:restriction base="xsd:string">                                                                       +
       </xsd:restriction>                                                                                        +
     </xsd:simpleType>                                                                                           +
                                                                                                                 +
     <xsd:complexType name="SchemaType.t1.testxmlschema">                                                        +
       <xsd:sequence>                                                                                            +
         <xsd:element name="test1" type="RowType.t1.testxmlschema.test1" minOccurs="0" maxOccurs="unbounded"/>   +
       </xsd:sequence>                                                                                           +
     </xsd:complexType>                                                                                          +
                                                                                                                 +
     <xsd:element name="testxmlschema" type="SchemaType.t1.testxmlschema"/>                                      +
                                                                                                                 +
     </xsd:schema>                                                                                               +
                                                                                                                 +
     <test1>                                                                                                     +
                                                                                                                 +
       <a>1</a>                                                                                                  +
       <b>one</b>                                                                                                +
     </test1>                                                                                                    +
                                                                                                                 +
     <test1>                                                                                                     +
                                                                                                                 +
       <a>2</a>                                                                                                  +
       <b>two</b>                                                                                                +
     </test1>                                                                                                    +
                                                                                                                 +
     <test1>                                                                                                     +
                                                                                                                 +
       <a>-1</a>                                                                                                 +
       <b xsi:nil="true"/>                                                                                       +
     </test1>                                                                                                    +
                                                                                                                 +
                                                                                                                 +
     </testxmlschema>                                                                                            +
    
    (1 row)
    

  • database_to_xml(nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个数据库的内容映射成XML文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    gaussdb=# SELECT database_to_xml(true, true, 'test');
                                  database_to_xml                              
    ---------------------------------------------------------------------------
     <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="test">+
                                                                              +
     <dbe_x005F_xml>                                                          +
                                                                              +
     </dbe_x005F_xml>                                                         +
                                                                              +
     <dbe_x005F_xmldom>                                                       +
                                                                              +
     </dbe_x005F_xmldom>                                                      +
                                                                              +
     <dbe_x005F_xmlparser>                                                    +
                                                                              +
     </dbe_x005F_xmlparser>                                                   +
                                                                              +
     <public>                                                                 +
                                                                              +
     </public>                                                                +
                                                                              +
     </test>                                                                  +
    
    (1 row)
    

  • database_to_xmlschema(nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个数据库的内容映射成XML模式文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    gaussdb=# SELECT database_to_xmlschema(true, true, 'test');
                                      database_to_xmlschema                                   
    ------------------------------------------------------------------------------------------
     <xsd:schema                                                                             +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"                                        +
         targetNamespace="test"                                                              +
         elementFormDefault="qualified">                                                     +
                                                                                             +
     <xsd:complexType name="CatalogType.test">                                               +
       <xsd:all>                                                                             +
         <xsd:element name="dbe_x005F_xml" type="SchemaType.test.dbe_x005F_xml"/>            +
         <xsd:element name="dbe_x005F_xmldom" type="SchemaType.test.dbe_x005F_xmldom"/>      +
         <xsd:element name="dbe_x005F_xmlparser" type="SchemaType.test.dbe_x005F_xmlparser"/>+
         <xsd:element name="public" type="SchemaType.test.public"/>                          +
       </xsd:all>                                                                            +
     </xsd:complexType>                                                                      +
                                                                                             +
     <xsd:element name="test" type="CatalogType.test"/>                                      +
                                                                                             +
     </xsd:schema>
    (1 row)
    

  • database_to_xml_and_xmlschema(nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将整个模式的内容映射成XML文档和XML模式文档,并把两个文档连接在一起。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    gaussdb=# SELECT database_to_xml_and_xmlschema(true, true, 'test');
                                         database_to_xml_and_xmlschema                                     
    -------------------------------------------------------------------------------------------------------
     <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="test" xsi:schemaLocation="test #">+
                                                                                                          +
     <xsd:schema                                                                                          +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"                                                     +
         targetNamespace="test"                                                                           +
         elementFormDefault="qualified">                                                                  +
                                                                                                          +
     <xsd:complexType name="CatalogType.test">                                                            +
       <xsd:all>                                                                                          +
         <xsd:element name="dbe_x005F_xml" type="SchemaType.test.dbe_x005F_xml"/>                         +
         <xsd:element name="dbe_x005F_xmldom" type="SchemaType.test.dbe_x005F_xmldom"/>                   +
         <xsd:element name="dbe_x005F_xmlparser" type="SchemaType.test.dbe_x005F_xmlparser"/>             +
         <xsd:element name="public" type="SchemaType.test.public"/>                                       +
       </xsd:all>                                                                                         +
     </xsd:complexType>                                                                                   +
                                                                                                          +
     <xsd:element name="test" type="CatalogType.test"/>                                                   +
                                                                                                          +
     </xsd:schema>                                                                                        +
                                                                                                          +
     <dbe_x005F_xml>                                                                                      +
                                                                                                          +
     </dbe_x005F_xml>                                                                                     +
                                                                                                          +
     <dbe_x005F_xmldom>                                                                                   +
                                                                                                          +
     </dbe_x005F_xmldom>                                                                                  +
                                                                                                          +
     <dbe_x005F_xmlparser>                                                                                +
                                                                                                          +
     </dbe_x005F_xmlparser>                                                                               +
                                                                                                          +
     <public>                                                                                             +
                                                                                                          +
     </public>                                                                                            +
                                                                                                          +
     </test>                                                                                              +
    
    (1 row)
    

  • table_to_xml(tbl regclass, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将关系表的内容映射成XML文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    gaussdb=# SELECT table_to_xml('testxmlschema.test1', false, false, '');
                             table_to_xml                          
    ---------------------------------------------------------------
     <test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                                  +
     <row>                                                        +
       <a>1</a>                                                   +
       <b>one</b>                                                 +
     </row>                                                       +
                                                                  +
     <row>                                                        +
       <a>2</a>                                                   +
       <b>two</b>                                                 +
     </row>                                                       +
                                                                  +
     <row>                                                        +
       <a>-1</a>                                                  +
     </row>                                                       +
                                                                  +
     </test1>                                                     +
    
    (1 row)
    

  • table_to_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将关系表的内容映射成XML模式文档。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    gaussdb=# SELECT table_to_xmlschema('testxmlschema.test1', false, false, '');
                                                   table_to_xmlschema                                                
    -----------------------------------------------------------------------------------------------------------------
     <xsd:schema                                                                                                    +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                                              +
                                                                                                                    +
     <xsd:simpleType name="INTEGER">                                                                                +
       <xsd:restriction base="xsd:int">                                                                             +
         <xsd:maxInclusive value="2147483647"/>                                                                     +
         <xsd:minInclusive value="-2147483648"/>                                                                    +
       </xsd:restriction>                                                                                           +
     </xsd:simpleType>                                                                                              +
                                                                                                                    +
     <xsd:simpleType name="UDT.regression.pg_catalog.text">                                                         +
       <xsd:restriction base="xsd:string">                                                                          +
       </xsd:restriction>                                                                                           +
     </xsd:simpleType>                                                                                              +
                                                                                                                    +
     <xsd:complexType name="RowType.regression.testxmlschema.test1">                                                +
       <xsd:sequence>                                                                                               +
         <xsd:element name="a" type="INTEGER" minOccurs="0"></xsd:element>                                          +
         <xsd:element name="b" type="UDT.regression.pg_catalog.text" minOccurs="0"></xsd:element>                   +
       </xsd:sequence>                                                                                              +
     </xsd:complexType>                                                                                             +
                                                                                                                    +
     <xsd:complexType name="TableType.regression.testxmlschema.test1">                                              +
       <xsd:sequence>                                                                                               +
         <xsd:element name="row" type="RowType.regression.testxmlschema.test1" minOccurs="0" maxOccurs="unbounded"/>+
       </xsd:sequence>                                                                                              +
     </xsd:complexType>                                                                                             +
                                                                                                                    +
     <xsd:element name="test1" type="TableType.regression.testxmlschema.test1"/>                                    +
                                                                                                                    +
     </xsd:schema>
    (1 row)
    

  • table_to_xml_and_xmlschema(tbl regclass, nulls boolean, tableforest boolean, targetns text)

    描述:该函数会将关系表的内容映射成XML文档和XML模式文档,并把两个文档连接在一起。

    返回值类型:XML

    示例:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    gaussdb=# SELECT table_to_xml_and_xmlschema('testxmlschema.test1', false, false, '');
                                               table_to_xml_and_xmlschema                                            
    -----------------------------------------------------------------------------------------------------------------
     <test1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="#">                +
                                                                                                                    +
     <xsd:schema                                                                                                    +
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">                                                              +
                                                                                                                    +
     <xsd:simpleType name="INTEGER">                                                                                +
       <xsd:restriction base="xsd:int">                                                                             +
         <xsd:maxInclusive value="2147483647"/>                                                                     +
         <xsd:minInclusive value="-2147483648"/>                                                                    +
       </xsd:restriction>                                                                                           +
     </xsd:simpleType>                                                                                              +
                                                                                                                    +
     <xsd:simpleType name="UDT.regression.pg_catalog.text">                                                         +
       <xsd:restriction base="xsd:string">                                                                          +
       </xsd:restriction>                                                                                           +
     </xsd:simpleType>                                                                                              +
                                                                                                                    +
     <xsd:complexType name="RowType.regression.testxmlschema.test1">                                                +
       <xsd:sequence>                                                                                               +
         <xsd:element name="a" type="INTEGER" minOccurs="0"></xsd:element>                                          +
         <xsd:element name="b" type="UDT.regression.pg_catalog.text" minOccurs="0"></xsd:element>                   +
       </xsd:sequence>                                                                                              +
     </xsd:complexType>                                                                                             +
                                                                                                                    +
     <xsd:complexType name="TableType.regression.testxmlschema.test1">                                              +
       <xsd:sequence>                                                                                               +
         <xsd:element name="row" type="RowType.regression.testxmlschema.test1" minOccurs="0" maxOccurs="unbounded"/>+
       </xsd:sequence>                                                                                              +
     </xsd:complexType>                                                                                             +
                                                                                                                    +
     <xsd:element name="test1" type="TableType.regression.testxmlschema.test1"/>                                    +
                                                                                                                    +
     </xsd:schema>                                                                                                  +
                                                                                                                    +
     <row>                                                                                                          +
       <a>1</a>                                                                                                     +
       <b>one</b>                                                                                                   +
     </row>                                                                                                         +
                                                                                                                    +
     <row>                                                                                                          +
       <a>2</a>                                                                                                     +
       <b>two</b>                                                                                                   +
     </row>                                                                                                         +
                                                                                                                    +
     <row>                                                                                                          +
       <a>-1</a>                                                                                                    +
     </row>                                                                                                         +
                                                                                                                    +
     </test1>                                                                                                       +
    
    (1 row)
    
说明:
  • xpath相关函数仅支持xpath()和xpath_exists(),由于其使用xpath语言查询XML文档,而这些函数都依赖于libxml2库,且这个库仅在Xpath1.0提供,所以对XPath的限制为1.0。
  • 不支持xquery、xml extension、xslt功能。
提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容