MCPcopy Create free account
hub / github.com/apache/cloudberry / xpath_string

Function xpath_string

contrib/xml2/xpath.c:310–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308PG_FUNCTION_INFO_V1(xpath_string);
309
310Datum
311xpath_string(PG_FUNCTION_ARGS)
312{
313 text *document = PG_GETARG_TEXT_PP(0);
314 text *xpathsupp = PG_GETARG_TEXT_PP(1); /* XPath expression */
315 xmlChar *xpath;
316 int32 pathsize;
317 text *xpres;
318 xmlXPathObjectPtr res;
319 xpath_workspace workspace;
320
321 pathsize = VARSIZE_ANY_EXHDR(xpathsupp);
322
323 /*
324 * We encapsulate the supplied path with "string()" = 8 chars + 1 for NUL
325 * at end
326 */
327 /* We could try casting to string using the libxml function? */
328
329 xpath = (xmlChar *) palloc(pathsize + 9);
330 memcpy((char *) xpath, "string(", 7);
331 memcpy((char *) (xpath + 7), VARDATA_ANY(xpathsupp), pathsize);
332 xpath[pathsize + 7] = ')';
333 xpath[pathsize + 8] = '\0';
334
335 res = pgxml_xpath(document, xpath, &workspace);
336
337 xpres = pgxml_result_to_text(res, NULL, NULL, NULL);
338
339 cleanup_workspace(&workspace);
340
341 pfree(xpath);
342
343 if (xpres == NULL)
344 PG_RETURN_NULL();
345 PG_RETURN_TEXT_P(xpres);
346}
347
348
349PG_FUNCTION_INFO_V1(xpath_number);

Callers

nothing calls this directly

Calls 5

pgxml_xpathFunction · 0.85
pgxml_result_to_textFunction · 0.85
cleanup_workspaceFunction · 0.85
pallocFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected