How to: Replicate to and from XML Files

Data Director can import and export data from XML files. The format used for the XML files is the same as generated by the T-SQL language.

Database connection string format: Database=<data folder>;|xml|none/attr

Where <data folder> is the location where the data files will be exported to or imported from, and 2 XML formats are supported, standard Element mode or Attribute mode. Each file should be named by Table name with .XML extension.

Example 1

Connection string: Database=c:\DBFiles;|xml|none

Data file name: Customer.xml

Copy
<Data>
  <row>
    <No.>011</No.>
    <Name>Spotsmeyer</Name>
    <SearchName>SPOTSMEYER</SearchName>>
    <Name2 />
    <Address>612 South Sunset Drive</Address>
  </row>
</Data>

T-SQL command to get same result: SELECT * from Customers FOR XML PATH, ROOT('Data')

Example 2

Connection string: Database=c:\DBFiles;|xml|attr

Data file name: Customer.xml

<Data>
<row No.=”011” Name=”Spotsmeyer” SearchName=”SPOTSMEYER” Name2=”” Address=”6 Str” />
</Data>

T-SQL command to get the same result: SELECT * from Customers FOR XML RAW, ROOT('Data')

When working with XML files, the Element and Attributes names cannot have special characters in the name so DD supports name conversion that will also be used when exporting the data

" " converts to _x0020_

"%" converts to _x0025_

"&" converts to _x0026_

"'" converts to _x0027_

"(" converts to _x0028_

")" converts to _x0029_

"/" converts to _x002F_

"<" converts to _x003C_

">" converts to _x003E_

"[" converts to _x005B_

"]" converts to _x005D_

"^" converts to _x005E_

So a field named “Search Name” will become “Search_x0020_Name” in the XML File, and should be set as same for DD to be able to import the data from the file.