# Setting up XML DB Connector

## **Create a Database Collection in SearchBlox**

  • After logging in to the Admin Console, select the Collections tab and click on Create a New Collection or "+" icon.

  • Choose Database Collection as Collection Type.

  • Enter a unique name for your collection (for example, XML).

  • Choose Private/Public Collection Access and Collection Encryption as per the requirements.

  • Choose the language of the content (if the language is other than English).

  • Click Save to create the collection.


## **XMLSample Data**

We will use the sample XML data given in the following for configuring SQL queries and database URL string. You can download the following data as a XML file, place it in a folder and follow the steps to test the DB connector.

  • The main object in this XML file is **people**

  • The structure of objects in the file is represented in the following table. [Learn more on Parsing XML Data](🔗)


**JSON Objects in the file**

## ** Database Collection Settings**

  • The mandatory settings for Database collection for External DB Connectors are Database Type Database URL String SQL Query

  • Select Database Type as XML from the dropdown menu.

  • Enter the Database URL String in the format as shown here: `jdbc:xml:DataModel=Relational;URI=C:\xmljson\person.xml;`

  • Provide the exact URI of your xml file.

  • Provide SQL Query, which fetches the data from XML file and saves it.


  • Save the settings.

  • Check the settings by clicking Test Database Collection. The database connection has to be successful for the indexing to work.

Configure SQL Query

  • To fetch data from the XML, a select SQL query must be provided.

  • It is mandatory to map a unique field to uid

  • The query should follow SQL SELECT query format with mappings. [SQL Query for Database Collection](🔗) `SELECT <index field> as uid , <column name2> as title, <column name3> as content FROM <tablename> LIMIT 100` **Sample Query for XML sample data:** `SELECT [people].[personal.name.first] AS uid, [people].[personal.name.last] AS title,[people].[personal.age] AS age,[people].[personal.gender] AS gender,[people].[vehicles.type],[people].[vehicles.model],[people].[vehicles.insurance.company],[people].[vehicles.maintenance.date] FROM [people]`

  • In the preceding query you can see the fields are representated interms of hierarchy example: `[people].[personal.name.first]` `[people].[vehicles.maintenance.date] `

[Reference for select queries for Database XML Connector](🔗)

  • If you have more than 100 entries in a table, specify the number of documents to be indexed by giving LIMIT value in the query. For example: `SELECT <index field> as uid , <column name2> as title, <column name3> as content FROM <tablename> LIMIT 100` Otherwise, a minimum of 50 rows will be indexed.


## **Schedule and Index**

Sets the frequency and the start date/time for indexing a collection. Schedule Frequency supported in SearchBlox is as follows:

  • Once

  • Hourly

  • Daily

  • Every 48 Hours

  • Every 96 Hours

  • Weekly

  • Monthly

The following operations can be performed in Database collections.

**Schedule**For each collection, indexing can be scheduled based on the above options.

To know more about Database Collection refer [Database Collection](🔗)


Search results in faceted search is shown here: