Skip to content

Query

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

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

Parameters

string xquery
    The XQuery expression to execute against the database.

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

string collection optional
    The name of the collection to query. If not specified, the domain database is queried.

Returns

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

Remarks

The examples below demonstrate how to query the domain database.

The query syntax is described in detail on the XQuery standard page.

Query all customer nodes as strings

1
2
var results = $XmlRepository.Query('//Customer');
$Xml.InnerXml( 'Customer', results.join() );

Query a customer by ID with parameters

1
2
3
4
var results = $XmlRepository.Query('//Customer[Id=$id]', {
id : $Xml.Evaluate('CustomerId')
 });
$Xml.InnerXml( 'Customers', results.join() );

Update a customer name with XQuery

1
2
3
$XmlRepository.Query('for $customer in //Customer[Id=$id] return replace value of node $customer/Name with "Lady Gaga"', {
   id : $Xml.Evaluate('CustomerId')
});

Insert a new XML node with XQuery

1
2
3
4
$XmlRepository.Query('insert node (<Kaynak><Id>{$newId}</Id><Ad>{$newName}</Ad></Kaynak>) as last into /KVKEnvanter/Tanimlar/Kaynaklar', {
    newId: newId,
    newName: name.trim()
});

Delete a record with an XQuery update

1
2
3
4
5
6
7
$XmlRepository.Query('let $nodeValue := fn:parse-xml-fragment($nodeValue)' +
                     'for $record in Relation[Id=$id]/RepHistory/RepHistoryRecord[InstanceId=$instanceId] return ' +
                     '(delete node $record)', {
   id : relationId,
   instanceId : $Xml.Evaluate('SelectedHistory/Id'),
   nodeValue : $Xml.SelectSingle('.').InnerXml()
});

Info

To query a process database, use the ,collection, keyword and provide the database's GUID.

For process databases, you can obtain the GUID using ,$Instance.ProcessId,.

Query a process database collection

1
2
3
4
var results = $XmlRepository.Query('collection("49551ed3-6229-408a-aaaa-eb510463acad")//Customer[Id=$id]', {
   id : $Xml.Evaluate('CustomerId')
 });
$Xml.InnerXml( 'Customers', results[0].Evaluate('Id') );

See Also