Skip to content

QueryXml

Executes an XQuery against the repository and returns the results as an array of XML nodes.

1
$XmlRepository.QueryXml(xquery: string, parameters?: object):Array<Xml>

Parameters

string xquery
    The XQuery expression to execute against the database. The syntax of the query is detailed. More information can be found on the XQuery standard page.

object parameters optional
    An object containing parameters to bind to the XQuery expression.

Returns

An array of Xml nodes representing the results of the XQuery. Returns an empty array if the query yields no results.

Remarks

Each result must be a single XML element; use $XmlRepository.Query for text or atomic results. The returned nodes are not attached to the pool data. Copy them with Xml.Copy or Xml.Sync.

See XML+Database for further information about domain and process databases.

Info

To query a process database, use the collection function in the query and provide the process ID.

For the current process, you can obtain it with $Instance.ProcessId.

Examples

Read values from query results

1
2
3
4
5
6
7
var customers = $XmlRepository.QueryXml('//Customer[City = $city]', {
    city : $Xml.Evaluate('City')
});

var names = customers.map(function (customer) {
    return customer.Evaluate('Name');
});

Copy the first result into the pool data

1
2
3
4
5
6
7
var results = $XmlRepository.QueryXml('//Customer[Id = $id]', {
    id : $Xml.Evaluate('CustomerId')
});

if (results.length > 0) {
    results[0].Copy('.', $Xml.SelectSingle('Customer'));
}

Synchronize rows with query results

1
2
3
4
5
6
7
var contacts = $XmlRepository.QueryXml('//Customer[Id = $id]/Contacts/Contact', {
    id : $Xml.Evaluate('CustomerId')
});

$Xml.Sync('Contacts/Contact', contacts, function () {
    return this.Evaluate('Id');
});

See Also