VOOZH about

URL: https://www.cdata.com/kb/tech/xml-jdbc-datagrip.rst

⇱ Query XML Data in DataGrip


Query XML Data in DataGrip

πŸ‘ Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Create a Data Source for XML in DataGrip and use SQL to query live XML data.

DataGrip is a database IDE that allows SQL developers to query, create, and manage databases. When paired with the CData JDBC Driver for XML, DataGrip can work with live XML data. This article shows how to establish a connection to XML data in DataGrip and use the table editor to load XML data.

Create a New Driver Definition for XML

The steps below describe how to create a new Data Source in DataGrip for XML.

  1. In DataGrip, click File -> New > Project and name the project πŸ‘ Creating a new DataGrip project.
  2. In the Database Explorer, click the plus icon () and select Driver. πŸ‘ Adding a new Driver.
  3. In the Driver tab:
    • Set Name to a user-friendly name (e.g. "CData XML Driver")
    • Set Driver Files to the appropriate JAR file. To add the file, click the plus (), select "Add Files," navigate to the "lib" folder in the driver's installation directory and select the JAR file (e.g. cdata.jdbc.xml.jar).
    • Set Class to cdata.jdbc.xml.XML.jar
  4. Click "Apply" then "OK" to save the Connection πŸ‘ A configured Driver (Salesforce is shown).

Configure a Connection to XML

  1. Once the connection is saved, click the plus (), then "Data Source" then "CData XML Driver" to create a new XML Data Source.
  2. In the new window, configure the connection to XML with a JDBC URL.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the XML JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

     java -jar cdata.jdbc.xml.jar
     

    Fill in the connection properties and copy the connection string to the clipboard.

    Connecting to Local or Cloud-Stored (Box, Google Drive, Amazon S3, SharePoint) XML Files

    CData Drivers let you work with XML files stored locally and stored in cloud storage services like Box, Amazon S3, Google Drive, or SharePoint, right where they are.

    Setting connection properties for local files

    Set the URI property to local folder path.

    Setting connection properties for files stored in Amazon S3

    To connect to XML file(s) within Amazon S3, set the URI property to the URI of the Bucket and Folder where the intended XML files exist. In addition, at least set these properties:

    • AWSAccessKey: AWS Access Key (username)
    • AWSSecretKey: AWS Secret Key

    Setting connection properties for files stored in Box

    To connect to XML file(s) within Box, set the URI property to the URI of the folder that includes the intended XML file(s). Use the OAuth authentication method to connect to Box.

    Dropbox

    To connect to XML file(s) within Dropbox, set the URI proprerty to the URI of the folder that includes the intended XML file(s). Use the OAuth authentication method to connect to Dropbox. Either User Account or Service Account can be used to authenticate.

    SharePoint Online (SOAP)

    To connect to XML file(s) within SharePoint with SOAP Schema, set the URI proprerty to the URI of the document library that includes the intended XML file. Set User, Password, and StorageBaseURL.

    SharePoint Online REST

    To connect to XML file(s) within SharePoint with REST Schema, set the URI proprerty to the URI of the document library that includes the intended XML file. StorageBaseURL is optional. If not set, the driver will use the root drive. OAuth is used to authenticate.

    Google Drive

    To connect to XML file(s) within Google Drive, set the URI property to the URI of the folder that includes the intended XML file(s). Use the OAuth authentication method to connect and set InitiateOAuth to GETANDREFRESH.

    The property is the controlling property over how your data is represented into tables and toggles the following basic configurations.

    • Document (default): Model a top-level, document view of your XML data. The data provider returns nested elements as aggregates of data.
    • FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
    • Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.

    See the Modeling XML Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.

    πŸ‘ Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)
  3. Set URL to the connection string, e.g.,
    jdbc:xml:URI=C:/people.xml;DataModel=Relational;
  4. Click "Apply" and "OK" to save the connection string πŸ‘ A configured Data Source (Salesforce is shown).

At this point, you will see the data source in the Data Explorer.

Execute SQL Queries Against XML

To browse through the XML entities (available as tables) accessible through the JDBC Driver, expand the Data Source.

πŸ‘ Exploring the data (Salesforce is shown.)

To execute queries, right click on any table and select "New" -> "Query Console."

πŸ‘ Opening a new Query Console.

In the Console, write the SQL query you wish to execute. For example:

SELECT [people].[personal.age] AS age, [people].[personal.gender] AS gender, [people].[personal.name.first] AS first_name, [people].[personal.name.last] AS last_name, [vehicles].[model], FROM [people] JOIN [vehicles] ON [people].[_id] = [vehicles].[people_id]
πŸ‘ Querying with SQL (Salesforce is shown.)

Download a free, 30-day trial of the CData JDBC Driver for XML and start working with your live XML data in DataGrip. Reach out to our Support Team if you have any questions.