Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
ea3b212f
Commit
ea3b212f
authored
Mar 22, 2007
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit newest version of xmlpath().
Nikolay Samokhvalov
parent
f317a037
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
17 deletions
+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
No files found.
src/backend/utils/adt/xml.c
View file @
ea3b212f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* 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);
...
@@ -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
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
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
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 */
#endif
/* USE_LIBXML */
...
@@ -2414,20 +2414,31 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, bool n
...
@@ -2414,20 +2414,31 @@ SPI_sql_row_to_xmlelement(int rownum, StringInfo result, char *tablename, bool n
#ifdef USE_LIBXML
#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
*
text
*
xml_xmlnodeto
text
(
xmlNodePtr
cur
)
xml_xmlnodeto
xmltype
(
xmlNodePtr
cur
)
{
{
xmlChar
*
str
;
xmlChar
*
str
;
text
*
result
;
xmltype
*
result
;
size_t
len
;
size_t
len
;
xmlBufferPtr
buf
;
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
);
str
=
xmlXPathCastNodeToString
(
cur
);
len
=
strlen
((
char
*
)
str
);
len
=
strlen
((
char
*
)
str
);
result
=
(
text
*
)
palloc
(
len
+
VARHDRSZ
);
result
=
(
text
*
)
palloc
(
len
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
len
+
VARHDRSZ
);
SET_VARSIZE
(
result
,
len
+
VARHDRSZ
);
memcpy
(
VARDATA
(
result
),
str
,
len
);
memcpy
(
VARDATA
(
result
),
str
,
len
);
}
return
result
;
return
result
;
}
}
...
@@ -2607,7 +2618,7 @@ xmlpath(PG_FUNCTION_ARGS)
...
@@ -2607,7 +2618,7 @@ xmlpath(PG_FUNCTION_ARGS)
{
{
Datum
elem
;
Datum
elem
;
bool
elemisnull
=
false
;
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
,
astate
=
accumArrayResult
(
astate
,
elem
,
elemisnull
,
XMLOID
,
elemisnull
,
XMLOID
,
CurrentMemoryContext
);
CurrentMemoryContext
);
...
...
src/test/regress/expected/xml.out
View file @
ea3b212f
...
@@ -404,9 +404,9 @@ SELECT table_name, view_definition FROM information_schema.views
...
@@ -404,9 +404,9 @@ SELECT table_name, view_definition FROM information_schema.views
-- Text XPath expressions evaluation
-- Text XPath expressions evaluation
SELECT xmlpath('/value', data) FROM xmltest;
SELECT xmlpath('/value', data) FROM xmltest;
xmlpath
xmlpath
---------
---------
-------------
{
one
}
{
<value>one</value>
}
{
two
}
{
<value>two</value>
}
(2 rows)
(2 rows)
SELECT xmlpath(NULL, NULL) IS NULL FROM xmltest;
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
...
@@ -431,3 +431,9 @@ SELECT xmlpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><l
{1,2}
{1,2}
(1 row)
(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
View file @
ea3b212f
...
@@ -212,3 +212,5 @@ SELECT xmlpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:pi
...
@@ -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
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']]);
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
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
View file @
ea3b212f
...
@@ -152,3 +152,4 @@ SELECT xmlpath(NULL, NULL) IS NULL FROM xmltest;
...
@@ -152,3 +152,4 @@ SELECT xmlpath(NULL, NULL) IS NULL FROM xmltest;
SELECT
xmlpath
(
''
,
'<!-- error -->'
);
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
(
'//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
(
'//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>'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment