$XmlRepository Query Executes an XQuery against the repository and returns the results as an array of strings.
$XmlRepository.Query(xquery: string, parameters: object, collection: string):Array<string>
Parameters string xquery The XQuery expression to execute against the database.
object parameters An object containing parameters to bind to the XQuery expression.
string collection 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.
The examples below demonstrate how to query the domain database. The syntax of the query is detailed. More information can be found on the XQuery standard page.
Find all customers: var results = $XmlRepository . Query ( '//Customer' );
$Xml . InnerXml ( 'Customer' , results . join () );
Find customer by ID: var results = $XmlRepository . Query ( '//Customer[Id=$id]' , {
id : $Xml . Evaluate ( 'CustomerId' )
});
$Xml . InnerXml ( 'Customers' , results . join () );
Update a customer's name: $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 node: $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: $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
,.
Querying a process database: 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