| 308 | PG_FUNCTION_INFO_V1(xpath_string); |
| 309 | |
| 310 | Datum |
| 311 | xpath_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 | |
| 349 | PG_FUNCTION_INFO_V1(xpath_number); |
nothing calls this directly
no test coverage detected