static xmlChar *pg_xmlCharStrndup(char *str, size_t len);
#endif /* USE_LIBXML */
+static void xmldata_root_element_start(StringInfo result, const char *eltname,
+ const char *xmlschema, const char *targetns,
+ bool top_level);
+static void xmldata_root_element_end(StringInfo result, const char *eltname);
static StringInfo query_to_xml_internal(const char *query, char *tablename,
const char *xmlschema, bool nulls, bool tableforest,
const char *targetns, bool top_level);
initStringInfo(&result);
+ if (!tableforest)
+ {
+ xmldata_root_element_start(&result, "table", NULL, targetns, true);
+ appendStringInfoChar(&result, '\n');
+ }
+
SPI_connect();
portal = SPI_cursor_find(name);
if (portal == NULL)
SPI_finish();
+ if (!tableforest)
+ xmldata_root_element_end(&result, "table");
+
PG_RETURN_XML_P(stringinfo_to_xmltype(&result));
}
(1 row)
-MOVE FIRST IN xc;
+SELECT cursor_to_xmlschema('xc'::refcursor, false, true, '');
+ cursor_to_xmlschema
+----------------------------------------------------------------------------------------------
+
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+(1 row)
+
+MOVE BACKWARD ALL IN xc;
SELECT cursor_to_xml('xc'::refcursor, 5, true, false, '');
- cursor_to_xml
----------------
- +
- one +
- +
- +
- +
- two +
- +
- +
+ cursor_to_xml
+---------------------------------------------------------------
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ one +
+ +
+ +
+ +
+ two +
+ +
+ +
+
+
(1 row)
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
HINT: You need to rebuild PostgreSQL using --with-libxml.
-MOVE FIRST IN xc;
+SELECT cursor_to_xmlschema('xc'::refcursor, false, true, '');
+ERROR: unsupported XML feature
+DETAIL: This functionality requires the server to be built with libxml support.
+HINT: You need to rebuild PostgreSQL using --with-libxml.
+MOVE BACKWARD ALL IN xc;
SELECT cursor_to_xml('xc'::refcursor, 5, true, false, '');
ERROR: unsupported XML feature
DETAIL: This functionality requires the server to be built with libxml support.
DECLARE xc CURSOR WITH HOLD FOR SELECT * FROM testxmlschema.test1 ORDER BY 1, 2;
SELECT cursor_to_xml('xc'::refcursor, 5, false, true, '');
-MOVE FIRST IN xc;
+SELECT cursor_to_xmlschema('xc'::refcursor, false, true, '');
+MOVE BACKWARD ALL IN xc;
SELECT cursor_to_xml('xc'::refcursor, 5, true, false, '');
SELECT cursor_to_xmlschema('xc'::refcursor, true, false, '');