Ready to get started?

Learn more or sign up for a free trial:

CData Sync

Replicate Multiple XML Accounts



Replicate multiple XML accounts to one or many databases.

CData Sync for XML is a stand-alone application that provides solutions for a variety of replication scenarios such as replicating sandbox and production instances into your database. Both Sync for Windows and Sync for Java include a command-line interface (CLI) that makes it easy to manage multiple XML connections. In this article we show how to use the CLI to replicate multiple XML accounts.

Configure XML Connections

You can save connection and email notification settings in an XML configuration file. To replicate multiple XML accounts, use multiple configuration files. Below is an example configuration to replicate XML to SQLite:

Windows

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>System.Data.SQLite</DatabaseProvider> <ConnectionString>URI=C:/people.xml;DataModel=Relational;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> <TaskSchedulerStartTime>09:51</TaskSchedulerStartTime> <TaskSchedulerInterval>Never</TaskSchedulerInterval> </CDataSync>

Java

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>org.sqlite.JDBC</DatabaseProvider> <ConnectionString>URI=C:/people.xml;DataModel=Relational;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> </CDataSync>

See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models XML APIs as bidirectional database tables and XML files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.

After setting the URI and providing any authentication values, set DataModel to more closely match the data representation to the structure of your data.

The DataModel 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.

Configure Queries for Each XML Instance

Sync enables you to control replication with standard SQL. The REPLICATE statement is a high-level command that caches and maintains a table in your database. You can define any SELECT query supported by the XML API. The statement below caches and incrementally updates a table of XML data:

REPLICATE people;

You can specify a file containing the replication queries you want to use to update a particular database. Separate replication statements with semicolons. The following options are useful if you are replicating multiple XML accounts into the same database:

You can use a different table prefix in the REPLICATE SELECT statement:

REPLICATE PROD_people SELECT * FROM people

Alternatively, you can use a different schema:

REPLICATE PROD.people SELECT * FROM people

Run Sync

After you have configured the connection strings and replication queries, you can run Sync with the following command-line options:

Windows

XMLSync.exe -g MyProductionXMLConfig.xml -f MyProductionXMLSync.sql

Java

java -Xbootclasspath/p:c:\sqlitejdbc.jar -jar XMLSync.jar -g MyProductionXMLConfig.xml -f MyProductionXMLSync.sql