Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
ea3b212f
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea3b212f
编写于
3月 22, 2007
作者:
B
Bruce Momjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Commit newest version of xmlpath().
Nikolay Samokhvalov
上级
f317a037
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
17 deletion
+37
-17
src/backend/utils/adt/xml.c
src/backend/utils/adt/xml.c
+24
-13
src/test/regress/expected/xml.out
src/test/regress/expected/xml.out
+10
-4
src/test/regress/expected/xml_1.out
src/test/regress/expected/xml_1.out
+2
-0
src/test/regress/sql/xml.sql
src/test/regress/sql/xml.sql
+1
-0
未找到文件。
src/backend/utils/adt/xml.c
浏览文件 @
ea3b212f
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.3
6 2007/03/22 20:14:58
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.3
7 2007/03/22 20:26:30
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -91,7 +91,7 @@ static xmlChar *xml_text2xmlChar(text *in);
static
int
parse_xml_decl
(
const
xmlChar
*
str
,
size_t
*
lenp
,
xmlChar
**
version
,
xmlChar
**
encoding
,
int
*
standalone
);
static
bool
print_xml_decl
(
StringInfo
buf
,
const
xmlChar
*
version
,
pg_enc
encoding
,
int
standalone
);
static
xmlDocPtr
xml_parse
(
text
*
data
,
XmlOptionType
xmloption_arg
,
bool
preserve_whitespace
,
xmlChar
*
encoding
);
static
text
*
xml_xmlnodeto
text
(
xmlNodePtr
cur
);
static
text
*
xml_xmlnodeto
xmltype
(
xmlNodePtr
cur
);
#endif
/* USE_LIBXML */
...
...
@@ -2414,20 +2414,31 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, bool n
#ifdef USE_LIBXML
/*
* Convert XML node to text (
return value only, it's not dumping
)
* Convert XML node to text (
dump subtree in case of element, return value otherwise
)
*/
text
*
xml_xmlnodeto
text
(
xmlNodePtr
cur
)
xml_xmlnodeto
xmltype
(
xmlNodePtr
cur
)
{
xmlChar
*
str
;
text
*
result
;
size_t
len
;
xmlChar
*
str
;
xmltype
*
result
;
size_t
len
;
xmlBufferPtr
buf
;
str
=
xmlXPathCastNodeToString
(
cur
);
len
=
strlen
((
char
*
)
str
);
result
=
(
text
*
)
palloc
(
len
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
len
+
VARHDRSZ
);
memcpy
(
VARDATA
(
result
),
str
,
len
);
if
(
cur
->
type
==
XML_ELEMENT_NODE
)
{
buf
=
xmlBufferCreate
();
xmlNodeDump
(
buf
,
NULL
,
cur
,
0
,
1
);
result
=
xmlBuffer_to_xmltype
(
buf
);
xmlBufferFree
(
buf
);
}
else
{
str
=
xmlXPathCastNodeToString
(
cur
);
len
=
strlen
((
char
*
)
str
);
result
=
(
text
*
)
palloc
(
len
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
len
+
VARHDRSZ
);
memcpy
(
VARDATA
(
result
),
str
,
len
);
}
return
result
;
}
...
...
@@ -2607,7 +2618,7 @@ xmlpath(PG_FUNCTION_ARGS)
{
Datum
elem
;
bool
elemisnull
=
false
;
elem
=
PointerGetDatum
(
xml_xmlnodeto
text
(
xpathobj
->
nodesetval
->
nodeTab
[
i
]));
elem
=
PointerGetDatum
(
xml_xmlnodeto
xmltype
(
xpathobj
->
nodesetval
->
nodeTab
[
i
]));
astate
=
accumArrayResult
(
astate
,
elem
,
elemisnull
,
XMLOID
,
CurrentMemoryContext
);
...
...
src/test/regress/expected/xml.out
浏览文件 @
ea3b212f
...
...
@@ -403,10 +403,10 @@ SELECT table_name, view_definition FROM information_schema.views
-- Text XPath expressions evaluation
SELECT xmlpath('/value', data) FROM xmltest;
xmlpath
---------
{
one
}
{
two
}
xmlpath
---------
-------------
{
<value>one</value>
}
{
<value>two</value>
}
(2 rows)
SELECT xmlpath(NULL, NULL) IS NULL FROM xmltest;
...
...
@@ -431,3 +431,9 @@ SELECT xmlpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><l
{1,2}
(1 row)
SELECT xmlpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
xmlpath
-------------------------
{<b>two</b>,<b>etc</b>}
(1 row)
src/test/regress/expected/xml_1.out
浏览文件 @
ea3b212f
...
...
@@ -212,3 +212,5 @@ SELECT xmlpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:pi
ERROR: no XML support in this installation
SELECT xmlpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc'], ARRAY['http://127.0.0.1']]);
ERROR: no XML support in this installation
SELECT xmlpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');
ERROR: no XML support in this installation
src/test/regress/sql/xml.sql
浏览文件 @
ea3b212f
...
...
@@ -152,3 +152,4 @@ SELECT xmlpath(NULL, NULL) IS NULL FROM xmltest;
SELECT
xmlpath
(
''
,
'<!-- error -->'
);
SELECT
xmlpath
(
'//text()'
,
'<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>'
);
SELECT
xmlpath
(
'//loc:piece/@id'
,
'<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>'
,
ARRAY
[
ARRAY
[
'loc'
],
ARRAY
[
'http://127.0.0.1'
]]);
SELECT
xmlpath
(
'//b'
,
'<a>one <b>two</b> three <b>etc</b></a>'
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录