Skip to content

ImportFromXml

Imports XML data into the specified table. If a record already exists in the table, it is updated. If no record exists, a new record is added to the table. Comparison is automatically done using the table's primary key.

1
myDataTable.ImportFromXml(options: QueryWithMappings):DataTable

Parameters

QueryWithMappings options
    An object specifying the import options. This may contain one or more of the following properties:

Returns

The current DataTable instance.

Remarks

ColumnsXPath is used to specify an additional secondary mapping path via an XPath expression.
This method does not call the DataTable.Save method after execution. If you want to save the changes, you need to explicitly call the Save method or use $Database.ImportFromXml instead.

Common use for importing data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var table = $Database.Get({
    Parameters : {
        TargetSchema : 'HR',
        TargetTable : 'Groups'
    }
});

table.ImportFromXml({
    XPath : 'Groups/Group'
});

table.Save();

Using a map function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
var table = $Database.Get({
    Parameters : {
        TargetSchema : 'HR',
        TargetTable : 'Groups'
    }
});

table.ImportFromXml({
    XPath : 'Groups/Group',
    map : function (node) {
        this.Id = node.Evaluate('../Id');
    }
});

table.Save();

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

See Also