Serialization Methods


You can serialize query results into a non-XML format using either of the following methods:

Using Standard Support

Table D-1 specifies default values for the parameters that control the process of serializing query results into XML, XHTML, HTML, or TEXT notation as specified by the XSLT 2.0 and XQuery 1.0 Serialization, W3C Recommendation 23 January 2007 located at: http://www.w3.org/TR/2007/REC-xslt-xquery-serialization-20070123/

Table D-1. Serialization Parameters 
Parameter
XML
XHTML
HTML
TEXT
Modifiable or
Hard coded
byte-order-mark
yes
yes
yes
yes
Hard coded
cdata-section-elements
empty
empty
empty
N/A
Modifiable
doctype-public
none
none
none
N/A
Modifiable
doctype-system
none
none
none
N/A
Modifiable
encoding
UTF-8
UTF-8
UTF-8
UTF-8
Modifiable
escape-uri-attributes
N/A
no
no
N/A
Hard coded
include-content-type
N/A
no
no
N/A
Hard coded
indent
no
no
no
N/A
Modifiable, has no effect for HTML
media-type
N/A
empty
empty
empty
Hard coded
method
xml
xhtml
html
text
Modifiable
normalization-form
NFC
NFC
NFC
NFC
Hard coded
omit-xml-declaration
yes
yes
N/A
N/A
Modifiable
standalone
omit
omit
N/A
N/A
Modifiable
undeclare-prefixes
no
no
no
N/A
Hard coded
use-character-maps
empty
empty
empty
empty
Hard coded
version
1.0
1.0
4.01
N/A
Modifiable, has no effect for XML and XHTML

To change a parameter value, use any of the following methods:

Example: Setting the Properties Object

Properties indentationProperties = new Properties(); 
indentationProperties.setProperty("indent", "yes"); 
indentationProperties.setProperty("omit-xml-declaration", "no"); 
System.out.println(xqSequence.getSequenceAsString(indentationProperties)); 

Example: Setting serialize in a Query

declare option ddtek:serialize "indent=yes, omit-xml-declaration=no"; 
doc("orders.xml") 

Example: Setting serialize in DDXQDataSource

DDXQDataSource ds = new DDXQDataSource(); 
ds.setJdbcUrl("jdbc:xquery:sqlserver://server1:1433;databaseName=stocks"); 
ds.setOptions("serialize=indent=yes,omit-xml-declaration=no"); 

Example: Using ddtek:serialize()

ddtek:serialize(<books><book/></books>, "indent=yes, omit-xml-declaration=no") 

Using the DataDirect XML Converters

To serialize query results using DataDirect XML Converters, set the serialization method parameter to a value listed in Table D-2.

Table D-2. Formats Supported by the DataDirect XML Converters
Format
Method Parameter Value
Base-64 encoded binary
Base-64
Base-2 to Base-36 encoded binary
Binary
Comma-Separated Values (CSV)
CSV
dBase II, dBase III, dBase III+, dBase IV, and dBase V
dBase_II, dBase_III, dBase_III_plus, dBase_IV, dBase_V
Data Interchange Format (DIF)
DIF
Electronic Data Interchange (EDI)
EDI
E-mail MBox (MBox)
MBox
HTML
HTML
Java .properties
JavaProps
JSON (JavaScript Object Notation)
JSON
Progress OpenEdge .d data dump
DotD
PYX
Pyx
Rich Text Format (RTF)
RTF
Super Data Interchange (SDI)
SDI (Super Data Interchange Format)
Symbolic Link (SYLK)
SYLK (Symbolic Link Format)
Tab-separated values text
TAB (tab-separated values)
Whole-line text
Line
Windows .ini
WinIni
Windows Write
WinWrite

Example: Setting the Properties Object

Properties serialization = new Properties(); 
serialization.setProperty("method", "EDI"); 
serialization.setProperty("encoding", "UTF-16"); 
serialization.setProperty("newline", "unix"); 
xqs.writeSequence(new FileOutputStream("/home/user1/message.x12",
   serialization); 

Example: Setting serialize in a Query

declare option ddtek:serialize "method=EDI,encoding=UTF-16,newline=unix"; 
doc("orders.xml") 

Example: Setting serialize in DDXQDataSource

DDXQDataSource ds = new DDXQDataSource(); 
ds.setJdbcUrl("jdbc:xquery:sqlserver://server1:1433;databaseName=stocks"); 
ds.setOptions("serialize=method=EDI,encoding=UTF-16,newline=unix"); 

Example: Using ddtek:serialize()

ddtek:serialize( 
<EANCOM> 
    <UNB> 
        <UNB01> 
            <UNB0101>UNOC</UNB0101> 
            <UNB0102>3</UNB0102> 
        </UNB01> 
        <UNB02> 
            <UNB0201>ISENDER</UNB0201> 
            <UNB0202>ZZZ</UNB0202> 
        </UNB02> 
        <UNB03> 
            <UNB0301>IRECIPIENT</UNB0301> 
            <UNB0302>ZZZ</UNB0302> 
        </UNB03> 
        <UNB04> 
            <UNB0401>080827</UNB0401> 
            <UNB0402>1514</UNB0402> 
        </UNB04> 
        <UNB05>ICONTROL</UNB05> 
    </UNB> 
    <ORDERS> 
        <UNH> 
            <UNH01>MESSAGENUMBER</UNH01> 
            <UNH02> 
                <UNH0201>ORDERS</UNH0201> 
                <UNH0202>D</UNH0202> 
                <UNH0203>96A</UNH0203> 
                <UNH0204>EN</UNH0204> 
                <UNH0205>EAN008</UNH0205> 
            </UNH02> 
        </UNH> 
        <BGM/> 
        <DTM><DTM01><DTM0101></DTM0101></DTM01></DTM> 
        <UNS><UNS01></UNS01></UNS> 
        <UNT/> 
    </ORDERS> 
    <UNZ/> 
</EANCOM> 
,"method=EDI, encoding=UTF-16, newline=unix")