Serialization Methods
You can serialize query results into a non-XML format using either of the following methods:
- Using the standard XQuery support to serialize query results into XML, XHTML, HTML, and TEXT formats.
- Using the DataDirect XML Converters to serialize query results into many other formats, such as Electronic Data Interchange (EDI) and Comma-Separated Values (CSV). See Table D-2 for a complete list of the formats supported by the XML Converters.
DataDirect XML Converters are installed with the DataDirect Data Integration Suite, which also includes DataDirect XQuery.
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/
To change a parameter value, use any of the following methods:
- Set the Properties object in the XQJ API.
- Set the serialize option declaration in a query.
- Set the serialize option declaration in DDXQDataSource.
- Use the function, ddtek:serialize.
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
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()
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.
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
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")