[MarkLogic Dev General] RE: How to convert a String to element type

Ashish Kumar a.kumar at mpstechnologies.com
Fri Jun 27 01:34:58 PDT 2008


I found a way to solve this.

 

1.	I set the request query still as string
2.	request.setNewStringVariable("query","<search:ashish>

<search:search-criteria>
<search:term><search:text>cell</search:text><search:element><search:local-na
me>Body</search:local-name></search:element></search:term>
<search-path>/Publisher/PublisherInfo</search-path><sort><sort-field
type=\"xs:string\">PublisherName</sort-field><sort-field-id>ChapterTitle</so
rt-field-id></sort></search:search-criteria>

</search:ashish>");

 

3.	In my xqy file

import module namespace search="http://www.marklogic.com/ps/lib/lib-search"
at "lib-search.xqy"

import module namespace search1="http://www.marklogic.com/ps/lib/lib-search"
at "lib-search-custom.xqy"

 

 define variable $query as xs:string external

let $newQuery := xdmp:unquote($query,"")

return

let $results :=search:search-results($newQuery//search:search-criteria,1,5)

 

 

Thanx.

Ashish

  _____  

From: Ashish Kumar [mailto:a.kumar at mpstechnologies.com] 
Sent: Tuesday, June 24, 2008 3:32 PM
To: 'general at developer.marklogic.com'
Subject: How to convert a String to element type

 

Hi I am evaluating MarkLogic server for our new project. 

I was trying to use lib-search library for searching. 

Following function accepts element.

define function search-results($search-criteria as
element(search:search-criteria), $start as xs:integer, $end as xs:integer)
as node()*

{

  get-search-results(build-search-string($search-criteria,
build-cts-query($search-criteria)), $start, $end)

}

 

We can invoke the same by 


import module namespace search="http://www.marklogic.com/ps/lib/lib-search"
at "lib-search.xqy"


import module namespace search1="http://www.marklogic.com/ps/lib/lib-search"
at "lib-search-custom.xqy"


search:search-results(<search:search-criteria><search:term><search:text>smit
h</search:text></search:term></search:search-criteria>


, 1, 5)


 


Same I was trying to invoke through java xcc library. But I get the
following exception


Exception in thread "main" com.marklogic.xcc.exceptions.XQueryException:
XDMP-AS: search1:search-results("<search:search-criteria>
<search:term><search:text>cell</search:...", 1, 5) -- Invalid coercion:
"<search:search-criteria> <search:term><search:text>cell</search:..." as
element(search:search-criteria)

in /libSearch-SearchSummary1.xqy, on line 5

expr: search1:search-results("<search:search-criteria>
<search:term><search:text>cell</search:...", 1, 5)

      at
com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse(Server
ExceptionHandler.java:31)

      at
com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(EvalReque
stController.java:68)

      at
com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(Abstrac
tRequestController.java:72)

      at
com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:280)

      at
com.marklogic.xcc.examples.ModuleRunner.invoke(ModuleRunner.java:117)

      at
com.marklogic.xcc.examples.ModuleRunner.invokeToSingleString(ModuleRunner.ja
va:131)

      at com.marklogic.xcc.examples.ModuleRunner.main(ModuleRunner.java:176)


 


Pointers to the above will be appreciated.


 


Thanx a ton in advance,


/Ashish 


 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20080627/bfbea269/attachment.html


More information about the General mailing list