ImportFromXml¶
Imports XML data into a specified table. For more details, see DataTable.ImportFromXml.
1 | |
Parameters¶
QueryWithMappings query
The query object that defines the import parameters.
Returns¶
The DataTable instance representing the imported data.
Remarks¶
This method is a wrapper for the DataTable.ImportFromXml and DataTable.Save methods.
The design of your XML data model and SQL table columns is key for ease of use. When XML node and table column names are identical, this method maps them automatically.
Each node selected by XPath is saved as a row: rows are matched by primary key, so existing rows are updated and new rows are inserted. Running the same import again does not create duplicates.
Map function A map function can be used to transform values before saving, for example, to encrypt a value before saving it to the database. Inside the function, this is the data row and the argument is the XML node of the row.
Info
By default, all matching columns and data model elements are automatically updated by name. If your table columns and data model names are different, you can provide a Map function to map columns to your data model manually.
Saving related rows with sub-queries¶
Assume there are two tables, Corporations and SubCorporations, with a one-to-many relation named SubCorporations from Corporations to SubCorporations. When the table columns have the same names as the XML fields, a sub-query saves each corporation together with its related rows. See $Database.ExportToXml for the matching XML structure.
Warning
Set the relation's update rule to "Cascade" to update related rows with sub-queries.
Examples¶
Save a repeating section to a table¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Transform values before saving¶
1 2 3 4 5 6 7 8 | |
Set a column from a parent node¶
1 2 3 4 5 6 7 8 9 | |
Update only selected columns¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Replace related rows while importing¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
Save rows with their related rows¶
1 2 3 4 5 6 7 8 | |