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
c9cab106
Commit
c9cab106
authored
Mar 23, 2009
by
Andrew Dunstan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove munging of xml and xpath params to xpath(). The XML must now be a well formed XML document.
parent
10795649
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
39 deletions
+17
-39
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+6
-1
src/backend/utils/adt/xml.c
src/backend/utils/adt/xml.c
+11
-38
No files found.
doc/src/sgml/func.sgml
View file @
c9cab106
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.47
2 2009/02/07 14:16:45 momji
an Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.47
3 2009/03/23 21:00:38 adunst
an Exp $ -->
<chapter
id=
"functions"
>
<title>
Functions and Operators
</title>
...
...
@@ -8447,6 +8447,11 @@ SELECT xmlagg(x) FROM (SELECT * FROM test ORDER BY y DESC) AS tab;
corresponding to the node set produced by the XPath expression.
</para>
<para>
The second argument must be a well formed XML document. In particular,
it must have a single root node element.
</para>
<para>
The third argument of the function is an array of namespace
mappings. This array should be a two-dimensional array with the
...
...
src/backend/utils/adt/xml.c
View file @
c9cab106
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.8
3 2009/01/07 13:44:37 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.8
4 2009/03/23 21:00:39 adunstan
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -3182,8 +3182,9 @@ xml_xmlnodetoxmltype(xmlNodePtr cur)
* to be the most useful one (array of XML functions plays a role of
* some kind of substitution for XQuery sequences).
*
* Workaround here: we parse XML data in different way to allow XPath for
* fragments (see "XPath for fragment" TODO comment inside).
* It is up to the user to ensure that the XML passed is in fact
* an XML document - XPath doesn't work easily on fragments without
* a context node being known.
*/
Datum
xpath
(
PG_FUNCTION_ARGS
)
...
...
@@ -3258,41 +3259,13 @@ xpath(PG_FUNCTION_ARGS)
xml_init
();
/*
* To handle both documents and fragments, regardless of the fact whether
* the XML datum has a single root (XML well-formedness), we wrap the XML
* datum in a dummy element (<x>...</x>) and extend the XPath expression
* accordingly. To do it, throw away the XML prolog, if any.
*/
if
(
len
>=
5
&&
xmlStrncmp
((
xmlChar
*
)
datastr
,
(
xmlChar
*
)
"<?xml"
,
5
)
==
0
)
{
i
=
5
;
while
(
i
<
len
&&
!
(
datastr
[
i
-
1
]
==
'?'
&&
datastr
[
i
]
==
'>'
))
i
++
;
if
(
i
==
len
)
xml_ereport
(
ERROR
,
ERRCODE_INTERNAL_ERROR
,
"could not parse XML data"
);
++
i
;
datastr
+=
i
;
len
-=
i
;
}
string
=
(
xmlChar
*
)
palloc
((
len
+
8
)
*
sizeof
(
xmlChar
));
memcpy
(
string
,
"<x>"
,
3
);
memcpy
(
string
+
3
,
datastr
,
len
);
memcpy
(
string
+
3
+
len
,
"</x>"
,
5
);
len
+=
7
;
string
=
(
xmlChar
*
)
palloc
((
len
+
1
)
*
sizeof
(
xmlChar
));
memcpy
(
string
,
datastr
,
len
);
string
[
len
]
=
'\0'
;
xpath_expr
=
(
xmlChar
*
)
palloc
((
xpath_len
+
3
)
*
sizeof
(
xmlChar
));
memcpy
(
xpath_expr
,
"/x"
,
2
);
memcpy
(
xpath_expr
+
2
,
VARDATA
(
xpath_expr_text
),
xpath_len
);
xpath_expr
[
xpath_len
+
2
]
=
'\0'
;
xpath_len
+=
2
;
xpath_expr
=
(
xmlChar
*
)
palloc
((
xpath_len
+
1
)
*
sizeof
(
xmlChar
));
memcpy
(
xpath_expr
,
VARDATA
(
xpath_expr_text
),
xpath_len
);
xpath_expr
[
xpath_len
]
=
'\0'
;
xmlInitParser
();
...
...
@@ -3307,7 +3280,7 @@ xpath(PG_FUNCTION_ARGS)
doc
=
xmlCtxtReadMemory
(
ctxt
,
(
char
*
)
string
,
len
,
NULL
,
NULL
,
0
);
if
(
doc
==
NULL
)
xml_ereport
(
ERROR
,
ERRCODE_INVALID_XML_DOCUMENT
,
"could not parse XML d
ata
"
);
"could not parse XML d
ocument
"
);
xpathctx
=
xmlXPathNewContext
(
doc
);
if
(
xpathctx
==
NULL
)
xml_ereport
(
ERROR
,
ERRCODE_OUT_OF_MEMORY
,
...
...
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