About the Examples
Each example is located in a separate directory beneath the examples directory:
ddxq_install_directory/examples/name_of_example
For example:
ddxq3_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:
- "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.
- "ResultRetrieval" shows how you can retrieve the results of an XQuery expression as SAX, StAX, or DOM.
- "ExternalVariables" shows binding Java variables to external XQuery variables.
- "ExternalFunctions" shows different types of external functions supported by DataDirect XQuery and how they can be used.
- "Connect" demonstrates some of DataDirect XQuery's advanced connection options.
- "CustomDocumentURIResolver" shows how to implement a custom URI resolver.
- "JNDIDataSource" shows how to persist and load a DDXQDataSource using a JNDI provider.
- "RDBMSUpdate" shows how to insert, update, and delete data stored in a relational database.
- "XMLQuery" shows how to query data in XML documents.
For information about how to use each of these examples, see the following sections.
XQJExecute
From the XQJExecute directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_fileis 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.
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.
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 variableExternalFunctions
From the ExternalFunctions directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_fileis 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.
Connect
Before using this example, you must edit two source configuration files located in the Connect directory:
You must specify the correct values for the following elements in these files: url, user, and password. In addition, in the config_advanced.xml file, you must enter the correct values for the name attributes for the catalog and schema elements. See "Using a Source Configuration File" for more information about source configuration files.
From the Connect 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 corresponds to the connection method you want to use:
1 - Connect using config_basic.xml source configuration file. 2 - Connect using config_advanced.xml source configuration file, this example shows the use of a table alias. 3 - Connect using config_advanced.xml source configuration file, this example shows the use of a target namespace for a database table. 4 - Connect using config_advanced.xml source configuration file, this example shows how to eliminate certain table columns from the SQL/XML view of the table. 5 - Connect using config_advanced.xml source configuration file, this example shows the use of a base URI. 6 - Connects using config_advanced.xml source configuration file, this example illustrates the use of DataDirect Spy for XQJ.CustomDocumentURIResolver
From the CustomURIResolver directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_fileis 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.
JNDIDataSource
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_fileis 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.
XMLQuery
From the XMLQuery directory, enter the following command line to execute the example:
Windows:
UNIX:
where
xquery_fileis 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.