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

Function xml_xpathobjtoxmlarray

src/backend/utils/adt/xml.c:3911–3975  ·  view source on GitHub ↗

* Convert an XML XPath object (the result of evaluating an XPath expression) * to an array of xml values, which are appended to astate. The function * result value is the number of elements in the array. * * If "astate" is NULL then we don't generate the array value, but we still * return the number of elements it would have had. * * Nodesets are converted to an array containing the nodes'

Source from the content-addressed store, hash-verified

3909 * to a single-element array containing the value's string representation.
3910 */
3911static int
3912xml_xpathobjtoxmlarray(xmlXPathObjectPtr xpathobj,
3913 ArrayBuildState *astate,
3914 PgXmlErrorContext *xmlerrcxt)
3915{
3916 int result = 0;
3917 Datum datum;
3918 Oid datumtype;
3919 char *result_str;
3920
3921 switch (xpathobj->type)
3922 {
3923 case XPATH_NODESET:
3924 if (xpathobj->nodesetval != NULL)
3925 {
3926 result = xpathobj->nodesetval->nodeNr;
3927 if (astate != NULL)
3928 {
3929 int i;
3930
3931 for (i = 0; i < result; i++)
3932 {
3933 datum = PointerGetDatum(xml_xmlnodetoxmltype(xpathobj->nodesetval->nodeTab[i],
3934 xmlerrcxt));
3935 (void) accumArrayResult(astate, datum, false,
3936 XMLOID, CurrentMemoryContext);
3937 }
3938 }
3939 }
3940 return result;
3941
3942 case XPATH_BOOLEAN:
3943 if (astate == NULL)
3944 return 1;
3945 datum = BoolGetDatum(xpathobj->boolval);
3946 datumtype = BOOLOID;
3947 break;
3948
3949 case XPATH_NUMBER:
3950 if (astate == NULL)
3951 return 1;
3952 datum = Float8GetDatum(xpathobj->floatval);
3953 datumtype = FLOAT8OID;
3954 break;
3955
3956 case XPATH_STRING:
3957 if (astate == NULL)
3958 return 1;
3959 datum = CStringGetDatum((char *) xpathobj->stringval);
3960 datumtype = CSTRINGOID;
3961 break;
3962
3963 default:
3964 elog(ERROR, "xpath expression result type %d is unsupported",
3965 xpathobj->type);
3966 return 0; /* keep compiler quiet */
3967 }
3968

Callers 1

xpath_internalFunction · 0.85

Calls 7

xml_xmlnodetoxmltypeFunction · 0.85
accumArrayResultFunction · 0.85
BoolGetDatumFunction · 0.85
CStringGetDatumFunction · 0.85
cstring_to_xmltypeFunction · 0.85
Float8GetDatumFunction · 0.50

Tested by

no test coverage detected