1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Add an xpath_exists() function. This is equivalent to XMLEXISTS except that

it offers support for namespace mapping.

Mike Fowler, reviewed by David Fetter
This commit is contained in:
Tom Lane
2010-08-08 19:15:27 +00:00
parent 46aa77c7bd
commit 4dfc457854
8 changed files with 205 additions and 39 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.99 2010/08/05 04:21:54 petere Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.100 2010/08/08 19:15:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -3541,3 +3541,27 @@ Datum xmlexists(PG_FUNCTION_ARGS)
return 0;
#endif
}
/*
* Determines if the node specified by the supplied XPath exists
* in a given XML document, returning a boolean. Differs from
* xmlexists as it supports namespaces and is not defined in SQL/XML.
*/
Datum
xpath_exists(PG_FUNCTION_ARGS)
{
#ifdef USE_LIBXML
text *xpath_expr_text = PG_GETARG_TEXT_P(0);
xmltype *data = PG_GETARG_XML_P(1);
ArrayType *namespaces = PG_GETARG_ARRAYTYPE_P(2);
int res_nitems;
xpath_internal(xpath_expr_text, data, namespaces,
&res_nitems, NULL);
PG_RETURN_BOOL(res_nitems > 0);
#else
NO_XML_SUPPORT();
return 0;
#endif
}