Re: [MarkLogic Dev General] using xdmp:eval in REST Service

2014-10-16 Thread Kapoor, Pragya
Hi David,


I tried logging in invoker:

let $_populate-map := for $each-param in $urlParams
let $param-value := xdmp:get-request-field($each-param)
 let $_ := 
xdmp:log(fn:concat("$param-value",$param-value))
...
logs:

2014-10-17 11:16:29.008 Info: rest-ingestion: 
module-invoker.xqy?format=xml&moduleName=add-document&requestDirectory=add&apiVersion=v1
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valuexml
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd-document
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valuev1
2014-10-17 11:16:29.013 Info: rest-ingestion: 
$param-value39932186-9cab-44e9-8f4f-7ebf45dabf8f
2014-10-17 11:16:29.309 Info: rest-ingestion: Ingestion Service End Point 
add-document.xqy  39932186-9cab-44e9-8f4f-7ebf45dabf8f
2014-10-17 11:16:29.309 Info: rest-ingestion: 
Path/processing/39932186-9cab-44e9-8f4f-7ebf45dabf8f/validDocs/
2014-10-17 11:16:29.309 Info: rest-ingestion: 
uri/docs/BONY_4076_REPO-GMR-2000.xml

So its xml at this stage.


At rewriter:


 case element(POST)
return
let $urlParams := let $paramNames:= 
xdmp:get-request-field-names()
  for $eachParam in 
$paramNames
  let $_ := 
xdmp:log(fn:concat("$eachParam",$eachParam))
  let $paramValue := 
xdmp:get-request-field($eachParam)
  let $_ := 
xdmp:log(fn:concat("$paramValue",$paramValue))
  return 
concat($eachParam,'=',$paramValue)​

logs:



From: general-boun...@developer.marklogic.com 
 on behalf of David Ennis 

Sent: Thursday, October 16, 2014 5:00 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

HI.

Yes, I had a look.  The first reason I thought of the xdmp:unquote was because 
of the multipart form post. We have a system where we get XML packed inside of 
json in the body of a post and use xdmp:unquote and this seemed similiar.

I concluded that this might have been similiar looking at your code

rewriter:
...
 case element(POST)
return
let $urlParams := let $paramNames:= 
xdmp:get-request-field-names()
  for $eachParam in 
$paramNames
  let $paramValue := 
xdmp:get-request-field($eachParam)


INvoker:
...

  let $_populate-map := for $each-param in $urlParams
let $param-value := xdmp:get-request-field($each-param) 
<- Still not XML at this stage, I would assume
...

Kind Regards,
David



Kind Regards,
David Ennis


David Ennis
Content Engineer

[HintTech] 
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[http://www.hinttech.com] 
[http://www.hinttech.com/signature/Twitter_HintTech.png] 
  
[http://www.hinttech.com/signature/Facebook_HintTech.png] 
  
[http://www.hinttech.com/signature/Linkedin_HintTech.png] 


On 16 October 2014 13:15, Kapoor, Pragya 
mailto:pkapo...@innodata.com>> wrote:

Hi,


Yes, I tried using xdmp:unquote on $contents but still not working.

Did you get a chance to look into the code which I attached in previous mail?

​

Thanks

Pragya


From: 
general-boun...@developer.marklogic.com
 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of David Ennis 
mailto:david.en...@hinttech.com>>
Sent: Thursday, October 16, 2014 2:41 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

HI.

I Know that this does not answer the whole question - but since things are 
getting serialized, have you tried xdmp:unquote on the serialized XML (the 
$contents variable in the original example)?

Kind Regards,
David Ennis




On 16 October 2014 06:44, Kapoor, Pragya 
mailto:pkapo...@innodata.com>> wrote:

Hi,


I am using Postman Rest Client to call this service. I am using POST method and 
sending parameters in form-data.

URL: 
http://{hostname}:8010/v1/addDocument


ML Version: 7.0-2.3​


I tried using xdmp:invoke instead of xdmp:eval but still the xml is getting 
serialized.


Attached is the code I am using.


Thanks

Pragya

__

Re: [MarkLogic Dev General] using xdmp:eval in REST Service

2014-10-16 Thread Kapoor, Pragya
​Hi,


I am unable to understand what your are trying to explain.

Can you explain in detail, what exactly is missing in the code.


Thanks

Pragya


From: general-boun...@developer.marklogic.com 
 on behalf of David Ennis 

Sent: Thursday, October 16, 2014 5:00 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

HI.

Yes, I had a look.  The first reason I thought of the xdmp:unquote was because 
of the multipart form post. We have a system where we get XML packed inside of 
json in the body of a post and use xdmp:unquote and this seemed similiar.

I concluded that this might have been similiar looking at your code

rewriter:
...
 case element(POST)
return
let $urlParams := let $paramNames:= 
xdmp:get-request-field-names()
  for $eachParam in 
$paramNames
  let $paramValue := 
xdmp:get-request-field($eachParam)


INvoker:
...

  let $_populate-map := for $each-param in $urlParams
let $param-value := xdmp:get-request-field($each-param) 
<- Still not XML at this stage, I would assume
...

Kind Regards,
David



Kind Regards,
David Ennis


David Ennis
Content Engineer

[HintTech] 
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[http://www.hinttech.com] 
[http://www.hinttech.com/signature/Twitter_HintTech.png] 
  
[http://www.hinttech.com/signature/Facebook_HintTech.png] 
  
[http://www.hinttech.com/signature/Linkedin_HintTech.png] 


On 16 October 2014 13:15, Kapoor, Pragya 
mailto:pkapo...@innodata.com>> wrote:

Hi,


Yes, I tried using xdmp:unquote on $contents but still not working.

Did you get a chance to look into the code which I attached in previous mail?

​

Thanks

Pragya


From: 
general-boun...@developer.marklogic.com
 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of David Ennis 
mailto:david.en...@hinttech.com>>
Sent: Thursday, October 16, 2014 2:41 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

HI.

I Know that this does not answer the whole question - but since things are 
getting serialized, have you tried xdmp:unquote on the serialized XML (the 
$contents variable in the original example)?

Kind Regards,
David Ennis




On 16 October 2014 06:44, Kapoor, Pragya 
mailto:pkapo...@innodata.com>> wrote:

Hi,


I am using Postman Rest Client to call this service. I am using POST method and 
sending parameters in form-data.

URL: 
http://{hostname}:8010/v1/addDocument


ML Version: 7.0-2.3​


I tried using xdmp:invoke instead of xdmp:eval but still the xml is getting 
serialized.


Attached is the code I am using.


Thanks

Pragya


From: 
general-boun...@developer.marklogic.com
 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of David Lee 
mailto:david@marklogic.com>>
Sent: Wednesday, October 15, 2014 5:26 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

Could you show your code for how you run this via the REST interface ?
Which version of ML, and what method of accessing REST ?

One thing that stands out is the use of Eval ... this can get tricky when 
embedding in other code because of the multiple layer of string escaping needed 
...
You also don’t need the functx import inside the eval but that’s a different 
issue.

Instead of xdmp:eval I prefer xdmp:invoke-function(
http://docs.marklogic.com/xdmp:invoke-function

This simplifies (eliminates) the need to construct XQuery from strings (so its 
safer from XQuery injection and less likely to be corrupted when created from
other code.

Your example could then become:

let $DirectoryListing :=
 xdmp:invoke-function(
 function() {
  xdmp:directory($Path)
 } ,
 
   {xdmp:database("Ingestion")}
 
)

With no need to pass in external parameters or add delcarations in the body or 
quote things.
Try this first - ...  it’s a good trick to learn to write easier and safer code.

But I suspect your real problem is something else - we need to see the code 
your running from REST

The only xdmp:log() I see is for the docURI
   xdmp:log(fn:concat("uri",$docUri))

So the code your showing us isnt likely the actual code your run

Re: [MarkLogic Dev General] Is there a way to extract worksheet metadata from an Excel 97/2003?

2014-10-16 Thread David Ennis
HI.

I believe that with the conversion licence, you can do what you want
with: xdmp:excel-convert

Barring that, you could always run openoffice as a headless server for
conversion purposes.

Kind Regards,
David Ennis





Kind Regards,
David Ennis


David Ennis
*Content Engineer*

[image: HintTech]  
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[image: http://www.hinttech.com] 
  


On 16 October 2014 20:00, Gary Russo  wrote:

> I need to extract worksheet metadata called “defined name” from Excel
> 97/2003 formatted spreadsheets.
>
>
>
> The ISYS xdmp:document-filter() API is limiting because it only extracts
> the text.
>
>
>
> It does not extract any worksheet metadata.
>
>
>
> Does anyone know of a workaround for this?
>
>
>
> My only thought is to upload the “Excel 97/2003” xls file and then convert
> it on the server to an “Excel 2010” xlsx format.
>
>
>
> Once it’s in an Excel 2010 format, I can easily extract the “defined name”
> metadata.
>
>
>
> This is what it looks like in “Excel 2010” files.
>
>
>
>   
> Revenue!$B$6:$B$15
> Revenue!$C$6:$C$15
> Revenue!$D$6:$D$15
>   
>
>
>
>
>
> Thanks,
>
> Gary Russo
>
>
>
>
>
> *Gary Russo*
>
> *Enterprise NoSQL Developer*
>
> *Phone: 212-404-8639 <212-404-8639>*
>
> *Skype: garyprusso*
>
> *http://garyrusso.wordpress.com *
>
>
>
> ___
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] Is there a way to extract worksheet metadata from an Excel 97/2003?

2014-10-16 Thread Gary Russo
I need to extract worksheet metadata called "defined name" from Excel
97/2003 formatted spreadsheets.

 

The ISYS xdmp:document-filter() API is limiting because it only extracts the
text.

 

It does not extract any worksheet metadata.

 

Does anyone know of a workaround for this?

 

My only thought is to upload the "Excel 97/2003" xls file and then convert
it on the server to an "Excel 2010" xlsx format.

 

Once it's in an Excel 2010 format, I can easily extract the "defined name"
metadata.

 

This is what it looks like in "Excel 2010" files.

 

  
Revenue!$B$6:$B$15
Revenue!$C$6:$C$15
Revenue!$D$6:$D$15
  

 

 

Thanks,

Gary Russo

 

 

Gary Russo

Enterprise NoSQL Developer

Phone: 212-404-8639

Skype: garyprusso

http://garyrusso.wordpress.com

 

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] word query

2014-10-16 Thread Danny Sokolsky
Have you tried this on 7.0-4?  There are some bugs fixed in this area there—it 
is worth a try.

What I recommend you do is create a simple test case using a simple cts:search 
with a cts:query that shows the issue, then post that here with the exact 
config info for it.  Otherwise we are just guessing.  The details are very 
important to understanding what is going on.

-Danny

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Girish Kulkarni
Sent: Thursday, October 16, 2014 9:39 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] word query

i am using word-constraint-query in my structured query and i see that when i 
exclude the enrichedDateTime , it does work in the sense i dont see any results 
when i search for the timestamp search i was seeing earlier. Now my only 
problem is i don't see other fields being searched. Well to be more specific i 
see that the results returned show total = 20 but i don't see anything being 
returned . As soon as i add the top level field  in the inclusion list i 
start seeing the 20 results.

Girish

On Wed, Oct 15, 2014 at 4:09 PM, Danny Sokolsky 
mailto:danny.sokol...@marklogic.com>> wrote:
Depending on what those structured queries are, they might not be word queries. 
 Excluding an element in the word query field does not mean you cannot query 
it, it just means that a cts:word-query will not see it.  For example, you can 
still see it in an element-word-query.

You say your reindexing started; did it complete?

-Danny

From: 
general-boun...@developer.marklogic.com
 
[mailto:general-boun...@developer.marklogic.com]
 On Behalf Of Girish Kulkarni
Sent: Wednesday, October 15, 2014 3:59 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] word query

As soon as i make changes to the word query , my database starts re-indexing.

We use marklogic 7.0-3 and we are using REST based structured queries. The 
query passes in a bunch of constraints and options , however i am just testing 
before and after scenario's based upon changes to the word query.

Girish

On Wed, Oct 15, 2014 at 3:55 PM, Danny Sokolsky 
mailto:danny.sokol...@marklogic.com>> wrote:
Did you reindex your database after changing the word query field?

Exactly what query are you running?

What version of MarkLogic are you using (xdmp:version() ).

-Danny

From: 
general-boun...@developer.marklogic.com
 
[mailto:general-boun...@developer.marklogic.com]
 On Behalf Of Girish Kulkarni
Sent: Wednesday, October 15, 2014 3:48 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] word query

I had some fileds in my xml document like enrichedDateTime which i didnt want 
to index and search upon. When i added this in the word query exclusion list 
for some reason my search result isn't returning back this document at all even 
when i searched for other field like . However when i added the  root 
field name  to my inclusion list i do see the document back again. I had 
already set the include root flag to true but seems like for some reason i am 
un-able to search for other fields in the document. Any ideas why this could be 
happening ?


 some content goes here 
2014-09-30T16:32:27.424443-07:00




Girish Kulkarni

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general



--
Girish Kulkarni

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general



--
Girish Kulkarni
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] word query

2014-10-16 Thread Girish Kulkarni
i am using word-constraint-query in my structured query and i see that when
i exclude the enrichedDateTime , it does work in the sense i dont see any
results when i search for the timestamp search i was seeing earlier. Now my
only problem is i don't see other fields being searched. Well to be more
specific i see that the results returned show total = 20 but i don't see
anything being returned . As soon as i add the top level field  in the
inclusion list i start seeing the 20 results.

Girish

On Wed, Oct 15, 2014 at 4:09 PM, Danny Sokolsky <
danny.sokol...@marklogic.com> wrote:

>  Depending on what those structured queries are, they might not be word
> queries.  Excluding an element in the word query field does not mean you
> cannot query it, it just means that a cts:word-query will not see it.  For
> example, you can still see it in an element-word-query.
>
>
>
> You say your reindexing started; did it complete?
>
>
>
> -Danny
>
>
>
> *From:* general-boun...@developer.marklogic.com [mailto:
> general-boun...@developer.marklogic.com] *On Behalf Of *Girish Kulkarni
> *Sent:* Wednesday, October 15, 2014 3:59 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] word query
>
>
>
> As soon as i make changes to the word query , my database starts
> re-indexing.
>
>
>
> We use marklogic 7.0-3 and we are using REST based structured queries. The
> query passes in a bunch of constraints and options , however i am just
> testing before and after scenario's based upon changes to the word query.
>
>
>
> Girish
>
>
>
> On Wed, Oct 15, 2014 at 3:55 PM, Danny Sokolsky <
> danny.sokol...@marklogic.com> wrote:
>
> Did you reindex your database after changing the word query field?
>
>
>
> Exactly what query are you running?
>
>
>
> What version of MarkLogic are you using (xdmp:version() ).
>
>
>
> -Danny
>
>
>
> *From:* general-boun...@developer.marklogic.com [mailto:
> general-boun...@developer.marklogic.com] *On Behalf Of *Girish Kulkarni
> *Sent:* Wednesday, October 15, 2014 3:48 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* [MarkLogic Dev General] word query
>
>
>
> I had some fileds in my xml document like enrichedDateTime which i didnt
> want to index and search upon. When i added this in the word query
> exclusion list for some reason my search result isn't returning back this
> document at all even when i searched for other field like .
> However when i added the  root field name  to my inclusion list i do
> see the document back again. I had already set the include root flag to
> true but seems like for some reason i am un-able to search for other fields
> in the document. Any ideas why this could be happening ?
>
>
>
> 
>  some content goes here 
> 2014-09-30T16:32:27.424443-07:00
> 
>
>
>
>
>
>
>
> Girish Kulkarni
>
>
> ___
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>
>
>
> --
> Girish Kulkarni
>
> ___
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>


-- 
Girish Kulkarni
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


[MarkLogic Dev General] Surprising slowness of cts:uri-match

2014-10-16 Thread Rachel Wilson
In our experience cts:uri-match is surprisingly slow.  For example when 
profiling a pretty complicated query taking 0.7 seconds, the single 
cts:uri-match() call takes 70-80% of the total time.  (Shallow% and Deep% being 
the same)

But we thought it should be reading the URI lexicon and so in a database with 
only 483,475 docs should be lightening fast.   We've had to stop using 
cts:uri-match calls in loops for this reason.

Are there any match patterns to be avoided perhaps?  Wildcards in the middle of 
the pattern, rather than trailing wildcards for example?
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] using xdmp:eval in REST Service

2014-10-16 Thread David Ennis
HI.

Yes, I had a look.  The first reason I thought of the xdmp:unquote was
because of the multipart form post. We have a system where we get XML
packed inside of json in the body of a post and use xdmp:unquote and this
seemed similiar.

I concluded that this might have been similiar looking at your code

*rewriter:*
...
 case element(POST)
return
let $urlParams := let $paramNames:=
xdmp:get-request-field-names()
  for $eachParam in
$paramNames
  let $paramValue
:= xdmp:get-request-field($eachParam)


*INvoker:*
...

  let $_populate-map := for $each-param in $urlParams
let $param-value :=
xdmp:get-request-field($each-param) <- Still not XML at this stage, I
would assume
...

Kind Regards,
David



Kind Regards,
David Ennis


David Ennis
*Content Engineer*

[image: HintTech]  
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[image: http://www.hinttech.com] 
  


On 16 October 2014 13:15, Kapoor, Pragya  wrote:

>  Hi,
>
>
>  Yes, I tried using xdmp:unquote on $contents but still not working.
>
> Did you get a chance to look into the code which I attached in previous
> mail?
>
> ​
>
> Thanks
>
> Pragya
>  --
> *From:* general-boun...@developer.marklogic.com <
> general-boun...@developer.marklogic.com> on behalf of David Ennis <
> david.en...@hinttech.com>
> *Sent:* Thursday, October 16, 2014 2:41 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>
>   HI.
>
> I Know that this does not answer the whole question - but since things are
> getting serialized, have you tried xdmp:unquote on the serialized XML (the
> $contents variable in the original example)?
>
> Kind Regards,
> David Ennis
>
>
>
>
> On 16 October 2014 06:44, Kapoor, Pragya  wrote:
>
>>  Hi,
>>
>>
>>  I am using Postman Rest Client to call this service. I am using POST
>> method and sending parameters in form-data.
>>
>> URL: http://{hostname}:8010/v1/addDocument
>> 
>>
>>
>>  ML Version: 7.0-2.3​
>>
>>
>>  I tried using xdmp:invoke instead of xdmp:eval but still the xml is
>> getting serialized.
>>
>>
>>  Attached is the code I am using.
>>
>>
>>  Thanks
>>
>> Pragya
>>  --
>> *From:* general-boun...@developer.marklogic.com <
>> general-boun...@developer.marklogic.com> on behalf of David Lee <
>> david@marklogic.com>
>> *Sent:* Wednesday, October 15, 2014 5:26 PM
>> *To:* MarkLogic Developer Discussion
>> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>>
>>
>> Could you show your code for how you run this via the REST interface ?
>>
>> Which version of ML, and what method of accessing REST ?
>>
>>
>>
>> One thing that stands out is the use of Eval ... this can get tricky when
>> embedding in other code because of the multiple layer of string escaping
>> needed ...
>>
>> You also don’t need the functx import inside the eval but that’s a
>> different issue.
>>
>> Instead of xdmp:eval I prefer xdmp:invoke-function(
>>
>> http://docs.marklogic.com/xdmp:invoke-function
>>
>>
>>
>> This simplifies (eliminates) the need to construct XQuery from strings
>> (so its safer from XQuery injection and less likely to be corrupted when
>> created from
>>
>> other code.
>>
>>
>>
>> Your example could then become:
>>
>>
>>
>> let $DirectoryListing :=
>>
>>  xdmp:invoke-function(
>>
>>  function() {
>>
>>   xdmp:directory($Path)
>>
>>  } ,
>>
>>  
>>
>>{xdmp:database("Ingestion")}
>>
>>  
>>
>> )
>>
>>
>>
>> With no need to pass in external parameters or add delcarations in the
>> body or quote things.
>>
>> Try this first - ...  it’s a good trick to learn to write easier and
>> safer code.
>>
>>
>>
>> But I suspect your real problem is something else - we need to see the
>> code your running from REST
>>
>>
>>
>> The only xdmp:log() I see is for the docURI
>>
>>xdmp:log(fn:concat("uri",$docUri))
>>
>>
>>
>> So the code your showing us isnt likely the actual code your running.
>>
>>
>>
>> Could you provide the code your running ?
>>
>> What library or language you using to call the REST APIS's ?
>>
>> What your showing looks like the results are being serialized as text
>> before you get them into
>>
>> let $DirectoryListing :=
>>
>>
>>
>>
>>
>>
>>
>>
>> -
>>
>> David Lee
>> Lead Engineer

Re: [MarkLogic Dev General] using xdmp:eval in REST Service

2014-10-16 Thread Kapoor, Pragya
Hi,


Yes, I tried using xdmp:unquote on $contents but still not working.

Did you get a chance to look into the code which I attached in previous mail?

​

Thanks

Pragya


From: general-boun...@developer.marklogic.com 
 on behalf of David Ennis 

Sent: Thursday, October 16, 2014 2:41 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

HI.

I Know that this does not answer the whole question - but since things are 
getting serialized, have you tried xdmp:unquote on the serialized XML (the 
$contents variable in the original example)?

Kind Regards,
David Ennis




On 16 October 2014 06:44, Kapoor, Pragya 
mailto:pkapo...@innodata.com>> wrote:

Hi,


I am using Postman Rest Client to call this service. I am using POST method and 
sending parameters in form-data.

URL: 
http://{hostname}:8010/v1/addDocument


ML Version: 7.0-2.3​


I tried using xdmp:invoke instead of xdmp:eval but still the xml is getting 
serialized.


Attached is the code I am using.


Thanks

Pragya


From: 
general-boun...@developer.marklogic.com
 
mailto:general-boun...@developer.marklogic.com>>
 on behalf of David Lee 
mailto:david@marklogic.com>>
Sent: Wednesday, October 15, 2014 5:26 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] using xdmp:eval in REST Service

Could you show your code for how you run this via the REST interface ?
Which version of ML, and what method of accessing REST ?

One thing that stands out is the use of Eval ... this can get tricky when 
embedding in other code because of the multiple layer of string escaping needed 
...
You also don’t need the functx import inside the eval but that’s a different 
issue.

Instead of xdmp:eval I prefer xdmp:invoke-function(
http://docs.marklogic.com/xdmp:invoke-function

This simplifies (eliminates) the need to construct XQuery from strings (so its 
safer from XQuery injection and less likely to be corrupted when created from
other code.

Your example could then become:

let $DirectoryListing :=
 xdmp:invoke-function(
 function() {
  xdmp:directory($Path)
 } ,
 
   {xdmp:database("Ingestion")}
 
)

With no need to pass in external parameters or add delcarations in the body or 
quote things.
Try this first - ...  it’s a good trick to learn to write easier and safer code.

But I suspect your real problem is something else - we need to see the code 
your running from REST

The only xdmp:log() I see is for the docURI
   xdmp:log(fn:concat("uri",$docUri))

So the code your showing us isnt likely the actual code your running.

Could you provide the code your running ?
What library or language you using to call the REST APIS's ?
What your showing looks like the results are being serialized as text before 
you get them into
let $DirectoryListing :=



-
David Lee
Lead Engineer
MarkLogic Corporation
d...@marklogic.com
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com

From: 
general-boun...@developer.marklogic.com
 
[mailto:general-boun...@developer.marklogic.com]
 On Behalf Of Kapoor, Pragya
Sent: Wednesday, October 15, 2014 3:59 AM
To: general@developer.marklogic.com
Subject: [MarkLogic Dev General] using xdmp:eval in REST Service

Hi,

I need to pick the all the docs in directory path ($Path) from Ingestion DB and 
insert them in Db which is configured for rest services(rest-ingestion).

The below code works fine from Qconsole, but from Rest service , the xml being 
picked from the Ingestion DB is not coming as xml when the code is hit from 
Rest service. In logs, only content is theres, xml elements are 
missing.(attached are the logs)

Please let me know, what I am missing in this code.

Thanks
Pragya

Code:

import module namespace dls = "http://marklogic.com/xdmp/dls";
  at "/MarkLogic/dls.xqy";

import module namespace functx = "http://www.functx.com";
at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";

let $transId := '39932186-9cab-44e9-8f4f-7ebf45dabf8f'
let $PrefixURI := "/docs/"

let $Path := fn:concat('/processing/', $transId,'/validDocs/')
let $DirectoryListing :=
xdmp:eval('
 import module namespace functx = 
"http://www.functx.com";
at 
"/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
 declare variable $Path as xs:string external;

  xdmp:directory($Path)
   

Re: [MarkLogic Dev General] using xdmp:eval in REST Service

2014-10-16 Thread David Ennis
HI.

I Know that this does not answer the whole question - but since things are
getting serialized, have you tried xdmp:unquote on the serialized XML (the
$contents variable in the original example)?

Kind Regards,
David Ennis




On 16 October 2014 06:44, Kapoor, Pragya  wrote:

>  Hi,
>
>
>  I am using Postman Rest Client to call this service. I am using POST
> method and sending parameters in form-data.
>
> URL: http://{hostname}:8010/v1/addDocument
> 
>
>
>  ML Version: 7.0-2.3​
>
>
>  I tried using xdmp:invoke instead of xdmp:eval but still the xml is
> getting serialized.
>
>
>  Attached is the code I am using.
>
>
>  Thanks
>
> Pragya
>  --
> *From:* general-boun...@developer.marklogic.com <
> general-boun...@developer.marklogic.com> on behalf of David Lee <
> david@marklogic.com>
> *Sent:* Wednesday, October 15, 2014 5:26 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>
>
> Could you show your code for how you run this via the REST interface ?
>
> Which version of ML, and what method of accessing REST ?
>
>
>
> One thing that stands out is the use of Eval ... this can get tricky when
> embedding in other code because of the multiple layer of string escaping
> needed ...
>
> You also don’t need the functx import inside the eval but that’s a
> different issue.
>
> Instead of xdmp:eval I prefer xdmp:invoke-function(
>
> http://docs.marklogic.com/xdmp:invoke-function
>
>
>
> This simplifies (eliminates) the need to construct XQuery from strings (so
> its safer from XQuery injection and less likely to be corrupted when
> created from
>
> other code.
>
>
>
> Your example could then become:
>
>
>
> let $DirectoryListing :=
>
>  xdmp:invoke-function(
>
>  function() {
>
>   xdmp:directory($Path)
>
>  } ,
>
>  
>
>{xdmp:database("Ingestion")}
>
>  
>
> )
>
>
>
> With no need to pass in external parameters or add delcarations in the
> body or quote things.
>
> Try this first - ...  it’s a good trick to learn to write easier and safer
> code.
>
>
>
> But I suspect your real problem is something else - we need to see the
> code your running from REST
>
>
>
> The only xdmp:log() I see is for the docURI
>
>xdmp:log(fn:concat("uri",$docUri))
>
>
>
> So the code your showing us isnt likely the actual code your running.
>
>
>
> Could you provide the code your running ?
>
> What library or language you using to call the REST APIS's ?
>
> What your showing looks like the results are being serialized as text
> before you get them into
>
> let $DirectoryListing :=
>
>
>
>
>
>
>
>
> -
>
> David Lee
> Lead Engineer
> *Mark**Logic* Corporation
> d...@marklogic.com
> Phone: +1 812-482-5224
>
> Cell:  +1 812-630-7622
> www.marklogic.com
>
>
>
> *From:* general-boun...@developer.marklogic.com [mailto:
> general-boun...@developer.marklogic.com] *On Behalf Of *Kapoor, Pragya
> *Sent:* Wednesday, October 15, 2014 3:59 AM
> *To:* general@developer.marklogic.com
> *Subject:* [MarkLogic Dev General] using xdmp:eval in REST Service
>
>
>
> Hi,
>
>
>
> I need to pick the all the docs in directory path ($Path) from Ingestion
> DB and insert them in Db which is configured for rest
> services(rest-ingestion).
>
>
>
> The below code works fine from Qconsole, but from Rest service , the xml
> being picked from the Ingestion DB is not coming as xml when the code is
> hit from Rest service. In logs, only content is theres, xml elements are
> missing.(attached are the logs)
>
>
>
> Please let me know, what I am missing in this code.
>
>
>
> Thanks
>
> Pragya
>
>
>
> Code:
>
>
>
> import module namespace dls = "http://marklogic.com/xdmp/dls";
>
>   at "/MarkLogic/dls.xqy";
>
>
>
> import module namespace functx = "http://www.functx.com";
>
> at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
>
>
>
> let $transId := '39932186-9cab-44e9-8f4f-7ebf45dabf8f'
>
> let $PrefixURI := "/docs/"
>
>
>
> let $Path := fn:concat('/processing/', $transId,'/validDocs/')
>
> let $DirectoryListing :=
>
> xdmp:eval('
>
>  import module namespace functx = "
> http://www.functx.com";
>
> at
> "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
>
>  declare variable $Path as xs:string external;
>
>
>
>   xdmp:directory($Path)
>
>  '
>
>  ,
>
>  (xs:QName("Path"), $Path)
>
>  ,
>
>  
>
>
>  {xdmp:database("Ingestion")}
>
>  
>
> )
>
> for $FileEntry