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

Function pgxml_xpath

contrib/xml2/xpath.c:413–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411/* Core function to evaluate XPath query */
412
413static xmlXPathObjectPtr
414pgxml_xpath(text *document, xmlChar *xpath, xpath_workspace *workspace)
415{
416 int32 docsize = VARSIZE_ANY_EXHDR(document);
417 PgXmlErrorContext *xmlerrcxt;
418 xmlXPathCompExprPtr comppath;
419
420 workspace->doctree = NULL;
421 workspace->ctxt = NULL;
422 workspace->res = NULL;
423
424 xmlerrcxt = pgxml_parser_init(PG_XML_STRICTNESS_LEGACY);
425
426 PG_TRY();
427 {
428 workspace->doctree = xmlParseMemory((char *) VARDATA_ANY(document),
429 docsize);
430 if (workspace->doctree != NULL)
431 {
432 workspace->ctxt = xmlXPathNewContext(workspace->doctree);
433 workspace->ctxt->node = xmlDocGetRootElement(workspace->doctree);
434
435 /* compile the path */
436 comppath = xmlXPathCompile(xpath);
437 if (comppath == NULL)
438 xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
439 "XPath Syntax Error");
440
441 /* Now evaluate the path expression. */
442 workspace->res = xmlXPathCompiledEval(comppath, workspace->ctxt);
443
444 xmlXPathFreeCompExpr(comppath);
445 }
446 }
447 PG_CATCH();
448 {
449 cleanup_workspace(workspace);
450
451 pg_xml_done(xmlerrcxt, true);
452
453 PG_RE_THROW();
454 }
455 PG_END_TRY();
456
457 if (workspace->res == NULL)
458 cleanup_workspace(workspace);
459
460 pg_xml_done(xmlerrcxt, false);
461
462 return workspace->res;
463}
464
465/* Clean up after processing the result of pgxml_xpath() */
466static void

Callers 5

xpath_nodesetFunction · 0.85
xpath_listFunction · 0.85
xpath_stringFunction · 0.85
xpath_numberFunction · 0.85
xpath_boolFunction · 0.85

Calls 4

pgxml_parser_initFunction · 0.85
xml_ereportFunction · 0.85
cleanup_workspaceFunction · 0.85
pg_xml_doneFunction · 0.85

Tested by

no test coverage detected