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();

See Also