Update of /cvsroot/monetdb/pathfinder/runtime
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25141
Modified Files:
serialize.mx serialize_dflt.mx
Log Message:
-- Extended our serialization with a new 'text' serialization mode.
This mode allows to serialize textnodes and strings without escaping.
E.g., the following XQuery query using the 'text' output mode results
in an unescaped text using angle brackets and quotes:
> cat textmode.xq
let $doc := <doc>
<a b="foo">[EMAIL PROTECTED]</a>
<a b="bar">[EMAIL PROTECTED]</a>
<a b="baz">[EMAIL PROTECTED]</a>
</doc>,
$list := for $x in $doc/a
return concat (""", $x/@b, "" <", $x, ">")
return string-join ($list, " ")
> MapiClient -l x -o text textmode.xq
"foo" <[EMAIL PROTECTED]>
"bar" <[EMAIL PROTECTED]>
"baz" <[EMAIL PROTECTED]>
Index: serialize_dflt.mx
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/runtime/serialize_dflt.mx,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- serialize_dflt.mx 1 Aug 2007 14:58:13 -0000 1.40
+++ serialize_dflt.mx 3 Aug 2007 16:09:45 -0000 1.41
@@ -206,6 +206,13 @@
* Emit a string with all entities escaped.
*/
@:emit_escaped(_entities,&& isspecial_ch <= 5)@
+/*
+ * This function is responsible for the presentation of special characters
+ * and XML entity characters in the result.
+ *
+ * Emit a string with only newlines escaped.
+ */
+@:emit_escaped(_newline,&& isspecial_ch == 5)@
/*
* This function is responsible for the presentation of special characters
@@ -586,6 +593,17 @@
}
/**
+ * Emit a String element of an XQUERY/Pathfinder result sequence
+ */
+static bool
+text_seqEmitStr (XqueryCtx* ctx, str sv)
+{
+ emit_escaped_newline (ctx, sv);
+
+ return SUCCESS;
+}
+
+/**
* Output generation handler. Handles top-level attributes.
*/
static bool
@@ -611,6 +629,23 @@
}
/**
+ * Output generation handler. Handles top-level attributes.
+ */
+static bool
+text_seqEmitAttribute (XqueryCtx* ctx, str prefix, str loc, str value)
+{
+ (void) ctx;
+ (void) prefix;
+ (void) loc;
+ (void) value;
+
+ GDKerror("serialize_dflt.mx: unable to print top level "
+ "attribute nodes in text mode\n");
+
+ return PROBLEM;
+}
+
+/**
* Output generation handler. Handles top-level textnodes.
*/
static bool
@@ -1130,6 +1165,78 @@
dm_seqItemSeparator
};
+struct serializeFunStruct textSerializeFun = {
+ "text",
+ dflt_init,
+ dflt_cleanup,
+
+ null_startSerialize,
+ null_endSerialize,
+
+ null_handle_startDocument,
+ null_handle_endDocument,
+ dflt_handle_startElement,
+ dflt_handle_endElement,
+ dflt_handle_characters,
+ dflt_handle_ignorableWhitespace,
+ dflt_handle_comment,
+ dflt_handle_processingInstruction,
+
+ dflt_complete_startElement,
+ dflt_complete_startElementEmpty,
+ dflt_handle_attribute,
+
+ dflt_seqEmitBool,
+ dflt_seqEmitInt,
+ dflt_seqEmitDbl,
+ text_seqEmitStr,
+ text_seqEmitAttribute,
+ text_seqEmitStr,
+
+ dm_seqStart,
+ null_complete_seqStart,
+ dm_seqEnd,
+ null_seqItemStart,
+ null_seqItemEnd,
+ null_seqItemSeparator
+};
+
+struct serializeFunStruct mapi_textSerializeFun = {
+ "text mapi",
+ mapi_init,
+ dflt_cleanup,
+
+ null_startSerialize,
+ null_endSerialize,
+
+ null_handle_startDocument,
+ null_handle_endDocument,
+ dflt_handle_startElement,
+ dflt_handle_endElement,
+ dflt_handle_characters,
+ dflt_handle_ignorableWhitespace,
+ dflt_handle_comment,
+ dflt_handle_processingInstruction,
+
+ dflt_complete_startElement,
+ dflt_complete_startElementEmpty,
+ dflt_handle_attribute,
+
+ dflt_seqEmitBool,
+ dflt_seqEmitInt,
+ dflt_seqEmitDbl,
+ text_seqEmitStr,
+ text_seqEmitAttribute,
+ text_seqEmitStr,
+
+ dm_seqStart,
+ null_complete_seqStart,
+ dm_seqEnd,
+ null_seqItemStart,
+ null_seqItemEnd,
+ null_seqItemSeparator
+};
+
struct serializeFunStruct xmlSerializeFun = {
"xml",
dflt_init,
Index: serialize.mx
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/runtime/serialize.mx,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- serialize.mx 24 Jul 2007 20:36:15 -0000 1.100
+++ serialize.mx 3 Aug 2007 16:09:41 -0000 1.101
@@ -89,13 +89,14 @@
/* serialization modes */
#define MODE_XML (1 << 0)
#define MODE_DM (1 << 1)
-#define MODE_SAX (1 << 2)
-#define MODE_MAPI (1 << 3)
-#define MODE_SEQ (1 << 4)
-#define MODE_NO_ROOT (1 << 5)
-#define MODE_NO_HEADER (1 << 6) /* without the line <?xml ...?> */
-#define MODE_TYPED (1 << 7)
-#define MODE_XRPC (1 << 8)
+#define MODE_TEXT (1 << 2)
+#define MODE_SAX (1 << 3)
+#define MODE_MAPI (1 << 4)
+#define MODE_SEQ (1 << 5)
+#define MODE_NO_ROOT (1 << 6)
+#define MODE_NO_HEADER (1 << 7) /* without the line <?xml ...?> */
+#define MODE_TYPED (1 << 8)
+#define MODE_XRPC (1 << 9)
struct XmlNsFrame; /* forward */
typedef struct XmlNsFrame {
@@ -214,6 +215,8 @@
saxSerializeFun,
dmSerializeFun,
mapi_dmSerializeFun,
+ textSerializeFun,
+ mapi_textSerializeFun,
xmlSerializeFun,
mapi_xmlSerializeFun,
typed_xmlSerializeFun,
@@ -1305,7 +1308,7 @@
/* reset the modes */
ctx->modes = 0;
- /* choose a mode: {xml, dm, sax} */
+ /* choose a mode: {xml, dm, text, sax} */
if (match(mode,"xml")) {
ctx->modes = MODE_XML;
@@ -1358,6 +1361,8 @@
ctx->modes = MODE_SEQ;
else if (match(mode,"dm"))
ctx->modes = MODE_DM;
+ else if (match(mode,"text"))
+ ctx->modes = MODE_TEXT;
else if (match(mode,"sax")) {
ctx->modes = MODE_SAX;
@@ -1380,7 +1385,8 @@
}
/* add mapi = characters at the start of each line */
- if ((ctx->modes & (MODE_DM | MODE_XML)) && match(mode,"mapi"))
+ if ((ctx->modes & (MODE_DM | MODE_TEXT | MODE_XML )) &&
+ match(mode,"mapi"))
ctx->modes = ctx->modes | MODE_MAPI;
@@ -1401,6 +1407,12 @@
else
ctx->driverFun = & dmSerializeFun;
}
+ else if ( ctx->modes & MODE_TEXT ) {
+ if ( ctx->modes & MODE_MAPI )
+ ctx->driverFun = & mapi_textSerializeFun;
+ else
+ ctx->driverFun = & textSerializeFun;
+ }
else if ( ctx->modes & MODE_XML ) {
if ( ctx->modes & MODE_MAPI && ctx->modes & MODE_TYPED )
ctx->driverFun = & mapi_typed_xmlSerializeFun;
@@ -1594,7 +1606,7 @@
/**
* Main XQUERY/Pathfinder result sequence printing routine.
* Arguments are
- * mode: e.g. "xml", "sax", "seq", "dm", ("noroot", "typed")
+ * mode: e.g. "xml", "sax", "seq", "dm", "text", ("noroot", "typed")
* ws : the working set
* max_iter : often [EMAIL PROTECTED] we can also print multiple iters for
XRPC or debugging
* item/item/kind : sequence result BATs (iter as a constant bat)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins