in ext/pg_query/pg_query_deparse.c [9175:9260]
static void deparseXmlExpr(StringInfo str, XmlExpr* xml_expr)
{
switch (xml_expr->op)
{
case IS_XMLCONCAT: /* XMLCONCAT(args) */
appendStringInfoString(str, "xmlconcat(");
deparseExprList(str, xml_expr->args);
appendStringInfoChar(str, ')');
break;
case IS_XMLELEMENT: /* XMLELEMENT(name, xml_attributes, args) */
appendStringInfoString(str, "xmlelement(name ");
appendStringInfoString(str, quote_identifier(xml_expr->name));
if (xml_expr->named_args != NULL)
{
appendStringInfoString(str, ", xmlattributes(");
deparseXmlAttributeList(str, xml_expr->named_args);
appendStringInfoString(str, ")");
}
if (xml_expr->args != NULL)
{
appendStringInfoString(str, ", ");
deparseExprList(str, xml_expr->args);
}
appendStringInfoString(str, ")");
break;
case IS_XMLFOREST: /* XMLFOREST(xml_attributes) */
appendStringInfoString(str, "xmlforest(");
deparseXmlAttributeList(str, xml_expr->named_args);
appendStringInfoChar(str, ')');
break;
case IS_XMLPARSE: /* XMLPARSE(text, is_doc, preserve_ws) */
Assert(list_length(xml_expr->args) == 2);
appendStringInfoString(str, "xmlparse(");
switch (xml_expr->xmloption)
{
case XMLOPTION_DOCUMENT:
appendStringInfoString(str, "document ");
break;
case XMLOPTION_CONTENT:
appendStringInfoString(str, "content ");
break;
default:
Assert(false);
}
deparseExpr(str, linitial(xml_expr->args));
if (strcmp(strVal(&castNode(A_Const, castNode(TypeCast, lsecond(xml_expr->args))->arg)->val), "t") == 0)
appendStringInfoString(str, " PRESERVE WHITESPACE");
appendStringInfoChar(str, ')');
break;
case IS_XMLPI: /* XMLPI(name [, args]) */
appendStringInfoString(str, "xmlpi(name ");
appendStringInfoString(str, quote_identifier(xml_expr->name));
if (xml_expr->args != NULL)
{
appendStringInfoString(str, ", ");
deparseExpr(str, linitial(xml_expr->args));
}
appendStringInfoChar(str, ')');
break;
case IS_XMLROOT: /* XMLROOT(xml, version, standalone) */
appendStringInfoString(str, "xmlroot(");
deparseExpr(str, linitial(xml_expr->args));
appendStringInfoString(str, ", version ");
if (nodeTag(&castNode(A_Const, lsecond(xml_expr->args))->val) == T_Null)
appendStringInfoString(str, "NO VALUE");
else
deparseExpr(str, lsecond(xml_expr->args));
if (intVal(&castNode(A_Const, lthird(xml_expr->args))->val) == XML_STANDALONE_YES)
appendStringInfoString(str, ", STANDALONE YES");
else if (intVal(&castNode(A_Const, lthird(xml_expr->args))->val) == XML_STANDALONE_NO)
appendStringInfoString(str, ", STANDALONE NO");
else if (intVal(&castNode(A_Const, lthird(xml_expr->args))->val) == XML_STANDALONE_NO_VALUE)
appendStringInfoString(str, ", STANDALONE NO VALUE");
appendStringInfoChar(str, ')');
break;
case IS_XMLSERIALIZE: /* XMLSERIALIZE(is_document, xmlval) */
// These are represented as XmlSerialize in raw parse trees
Assert(false);
break;
case IS_DOCUMENT: /* xmlval IS DOCUMENT */
Assert(list_length(xml_expr->args) == 1);
deparseExpr(str, linitial(xml_expr->args));
appendStringInfoString(str, " IS DOCUMENT");
break;
}
}