0
votes

Marklogic 9 and above no longer supports xcc connection for.NET applications and instead rest api shall be used.

I have been working on a POC and got my db instances exposed through a REST API creating REST API instances for each db. I have also been able to do simple search queries using GET. I have also used PUT and DELETE.

My problem is converting existing 140+ cts queries to xml body. There is an example here but uses a simple cts query, I would like some help on converting more complex queries into xml body - so I can use those against the api I have created.

Fore example:

How could I write this cts query in xml?

<ArrayOfRecord>
{{
cts:search(collection('Records{0}')/Record,
cts:and-query((
cts:element-range-query(xs:QName('CreatedOn'), '>=', xs:dateTime('{1}')),
cts:element-range-query(xs:QName('CreatedOn'), '<=', xs:dateTime('{2}')),
cts:path-range-query('/Record/IsLatestVersion', '=', 
'{3}')additionalQueries)))   
}}
</ArrayOfRecord>

Thanks

1
If you already have snippets of code you'd like to execute, how about saving them as .xqy text documents in an app-specific modules database, and invoke those via HTTP calls. You are not required to use the REST-api, though it does come with some conveniences that may or may not be useful in your case.. - grtjn
Thanks for your answer, I had considered that option, but it is not what I am trying to achieve here. - Vergil C.

1 Answers

2
votes

What you showed is a search, not just the cts:query, but if you just want to serialize a cts:query to XML, you can use a trick like this: <wrapper>{your query constructor here}</wrapper>.

For example:

xquery version "1.0-ml";
<wrapper>{cts:word-query("foo")}</wrapper>/*

Another possibility, which perhaps is too similar to Dave Cassel's suggestion for you, would be to use the REST Client API eval endpoint. You can use it to execute ad hoc XQuery (or Server-Side JavaScript), just as XCC enabled. Take a look at this: http://docs.marklogic.com/REST/POST/v1/eval