About the Examples
Each example is located in a separate directory beneath the examples directory:
ddxq_install_directory/examples/name_of_example
For example:
ddxq5_0/examples/xqjexecute
Each example directory contains the following files:
- run.bat or run.sh to execute the example program. This file contains a commented line, that when uncommented, recompiles the example.
- Zero or more .xq files that contain the XQuery expressions that will be executed by the example program.
- Zero or more .xml files that contain XML files that will be queried by the XQuery expressions.
- One or more source and class files that contain the source and compiled source code for the example.
The following examples are provided with the product:
- CustomDocumentURIResolver shows how to implement a custom URI resolver.
- JNDIDataSource shows how to persist and load a DDXQDataSource using a JNDI provider.
- ExternalFunctions shows different types of external functions supported by DataDirect XQuery and how they can be used.
- ExternalVariables shows binding Java variables to external XQuery variables.
- RDBMSUpdate shows how to insert, update, and delete data stored in a relational database.
- ResultRetrieval shows how you can retrieve the results of an XQuery expression as SAX, StAX, or DOM.
- UpdateFacility shows how to update data in XML documents.
- XMLQuery shows how to query data in XML documents.
- XQJExecute is a simple XQJ example that shows how to execute an XQuery expression from a file or string and retrieve the results as a string.
For information about how to use each of these examples, see the following sections.
CustomDocumentURIResolver
From the CustomURIResolver directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is the XQuery file you want to execute. If you do not specify a query file name, the XQuery file in the CustomURIResolver directory is executed. Optionally, you can write your own query, save it to a file, and execute that XQuery file by entering the file name as the argument to run.bat or run.sh.This example returns an XML document that contains a top-level directory element and a child element named file that represents each XML file found in the specified directory. The file element has a size attribute with a value of the file size in bytes, and the value of the file element is the name of the XML file. For example:
The resulting XML structure can be used in other XQuery expressions, as shown in the query of this example.
ExternalFunctions
From the ExternalFunctions directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is one of the following query files in the ExternalFunctions directory:
- javaFunction.xq invokes a static Java method.
- javaInstanceMethod.xq invokes a Java instance method.
- sqlFunction.xq invokes a SQL function.
- sqlFunctionFromModule_db2luw.xq invokes a SQL function from a module that declares SQL functions for DB2 for Linux/UNIX/Windows.
- sqlFunctionFromModule_ora.xq invokes a SQL function from a module that declares SQL functions for Oracle.
- sqlFunctionFromModule_sqlserver.xq invokes a SQL function from a module that declares SQL functions for Microsoft SQL Server.
- jdbcEscapeFunction.xq invokes a JDBC escape function.
If you do not specify an XQuery file in the command line, a prompt appears asking you to enter a number that corresponds to the XQuery file you want to execute.
The result of the query is written to standard output.
ExternalVariables
From the ExternalVariables directory, enter the following command line to execute the example:
Windows:
UNIX:
A prompt appears asking you to enter one of the following numbers that correspond to the type of external variable you want to execute:
1 - Bind an xs:int external variable 2 - Bind an xs:string external variable 3 - Bind a DOM node to an external variable 4 - Bind an XQItem to an external variable 5 - Bind an XQSequence to an external variableJNDIDataSource
Before using this example, you must have a JNDI provider on your machine. If you do not have one, you can download one from:
You must place the providerutil.jar and fscontext.jar files in your CLASSPATH. You can edit the setenv.bat (Windows) or setenv.sh (UNIX/Linux) files to do this.
From the JNDIDataSource directory, enter the following command line to execute the example:
Windows:
UNIX:
RDBMSUpdate
From the RDBMSUpdate directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is one of the following query files in the RDBMSUpdate directory:
- insert-holdings.xq inserts data into the holdings table.
- update-holdings.xq updates data in the holdings table.
- delete-holdings.xq deletes data from the holdings table.
- update-holdings-from-xml.xq uses data provided in an XML document to update data in the holdings table.
- update-function.xq updates data in the holdings table using a user-defined function.
- shredding-xml.xq shreds data provided in an XML document into multiple tables.
If you do not specify a query file name, a prompt appears asking you to enter the number that corresponds to the XQuery file you want to use:
1 - insert-holdings.xq 2 - update-holdings.xq 3 - delete-holdings.xq 4 - update-holdings-from-xml.xq 5 - update-function.xq 6 - shredding-xml.xqOptionally, you can write your own query, save it to a file, and execute that XQuery file by entering the file name as the argument to run.bat or run.sh.
ResultRetrieval
From the ResultRetrieval directory, enter the following command line to execute the example:
Windows:
UNIX:
A prompt appears asking you to enter one of the following numbers that correspond to the type of retrieval method you want to use:
The results of the retrieval method are displayed in the standard output.
UpdateFacility
From the UpdateFacility directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is one of the following query files in the UpdateFacility directory:
- change-values.xq uses the replace expression to replace the node value of a queried document .
- insert-nodes.xq uses the insert expression to insert a new node.
- rename-nodes.xq uses the rename expression to rename an existing node.
- transform-change-values.xq uses copy, modify, and return clauses to replace the value of an existing node.
- transform-insert-nodes.xq uses copy, modify, and return clauses to insert a new node.
If you do not specify a query file name, a prompt appears asking you to enter the number that corresponds to the XQuery file you want to use:
1 - rename-nodes.xq 2 - change-values.xq 3 - insert-nodes.xq 4 - transform-change-values.xq 5 - transfor-insert-nodes.xqOptionally, you can write your own query, save it to a file, and execute that XQuery file by entering the file name as the argument to run.bat or run.sh.
XMLQuery
From the XMLQuery directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is one of the following query files in the XMLQuery directory:
- query-initial-context.xq queries the initial context document.
- query-doc-function.xq queries an XML document using the fn:doc() function.
- query-external-variable.xq queries an XML document using an external variable.
- query-directory.xq queries multiple XML documents contained in the same directory.
- query-pipeline-1.xq uses the result of a one XQuery to provide input into another XQuery.
If you do not specify a query file name, a prompt appears asking you to enter the number that corresponds to the XQuery file you want to use:
1 - query-initial-context.xq 2 - query-doc-function.xq 3 - query-external-variable.xq 4 - query-directory.xq 5 - query-pipeline-1.xqOptionally, you can write your own query, save it to a file, and execute that XQuery file by entering the file name as the argument to run.bat or run.sh.
XQJExecute
From the XQJExecute directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_file
is one of the following query files in the XQJExecute directory:
- collection-users.xq returns all data from the users table.
- collection-holdings.xq returns all data from the holdings table.
- flwor.xq joins data from two relational tables using a nested FLWOR expression.
- JoinXMLToRelational.xq joins data from an XML file with data from a relational table.
- function.xq uses local function declarations.
- portfolioHTML.xq serializes the query result as HTML.
- MainModule.xq and LibraryModule.xq use XQuery modules.
- nodeId.xq uses a path expression to eliminate duplicate XML nodes.
If you do not specify an XQuery file in the command line, a prompt appears asking you to enter a number that corresponds to the XQuery file you want to execute. Or, you can enter the number "9" and then type in the text of your own query, which will be executed.