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.
Map Function
A map function can be used to transform values before saving, for example, encrypting a password before saving it to the database. See $Database.ExportToXml
for more details.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Common use case for importing data:¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Customized Column Update:¶
1 2 3 4 5 6 7 8 9 10 11 12 |
|
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 manually map columns to your data model.
Update Only Selected Columns:¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Nested Insert and Update:¶
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 26 27 28 29 |
|
Saving columns with their related single/multiple entities is handled as below.
Column Update with SubQueries:¶
1 2 3 4 5 6 7 8 9 10 11 |
|
Assume you have the XML below as your form data, two SQL tables Corporations and SubCorporations, and a One-To-Many relation from Corporations table to SubCorporations table which is also named SubCorporations.
Warning
Don't forget to set this relation's update rule to "Cascade" to update with sub-queries.
Having defined the table columns with identical names to the XML fields, this code lets you save each corporation from XML data into the SQL table, saving also its related SubCorporations into the related SQL table.
Form XML Example:¶
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 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
Types¶
QueryWithMappings¶
Defines a query with mappings to an XML structure.
Columns
: Array<QueryColumn>
An array of columns to include in the result set.
Map
: (node: Xml) => void
MaxLength
: number
The maximum number of rows to return. If not set, all rows are returned.
Node
: Xml
The root node for the mapping. If not specified, the
Order
: Array<QueryOrder>
An array of order expressions to sort the results.
Parameters
: object
Additional parameters to pass to the query.
Start
: number
The starting index for the rows to return.
SubQueries
: Array<SubQuery>
An array of sub-queries to include in the result set.
TargetSchema
: string
The name of the schema to execute the query against.
TargetTable
: string
The name of the table to execute the query against.
Where
: QueryBlock
The criteria to filter the query results.
XPath
: string
The root XPath expression to map the data to.
QueryColumn¶
Defines a query column to be included in the result set.
Expression
: string
An expression for the column, which can be a calculation or transformation.
Name
: string
The name of the column to use in the results. If not specified, the
XPath
: string
An XPath expression to map data to the column.
QueryOrder¶
Defines the ordering expression for the query results.
Expression
: string
The expression to use for ordering the results.
Type
: ( "Ascending"
| "Descending"
)
The type of ordering (ascending or descending). If not specified, defaults to "Ascending".
SubQuery¶
Defines a sub-query to include within a main query.
Columns
: Array<QueryColumn>
An array of columns to include in the result set.
MaxLength
: number
The maximum number of rows to return. If not set, all rows are returned.
Name
: string
The name of the sub-query. The relation name can be used as the name.
Order
: Array<QueryOrder>
An array of order expressions to sort the results.
Parameters
: object
Additional parameters to pass to the query.
Relation
: string
The name of the relation to use for the sub-query.
Start
: number
The starting index for the rows to return.
SubQueries
: Array<SubQuery>
An array of sub-queries to include in the result set.
TargetSchema
: string
The name of the schema to execute the query against.
TargetTable
: string
The name of the table to execute the query against.
Where
: QueryBlock
The criteria to filter the query results.
XPath
: string
The XPath expression to export the data to.
QueryBlock¶
Defines a block of criteria to group conditions within a query.
Blocks
: Array<QueryBlock>
An array of nested query blocks.
Condition
: ( "And"
| "Or"
)
The condition to combine this block with the next one. If not specified, defaults to "And".
Criteria
: Array<QueryCriteria>
An array of criteria to apply within this block.
QueryCriteria¶
Defines a criteria to filter the query results.
Comparison
: ( "Equals"
| "Different"
| "LessThan"
| "GreaterThan"
| "LessThanOrEqualTo"
| "GreaterThanOrEqualTo"
| "Like"
)
The comparison operator to use. Defaults to "Equals".
Condition
: ( "And"
| "Or"
)
The condition to combine this criteria with the next one. If not specified, defaults to "And".
Expression
: string
An expression for the criteria.
IgnoredValues
: any
An array of values to ignore.
Value
: any
The value or expression to compare against.
ValueType
: ( "Direct"
| "Expression"
)
The type of the