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 <[email protected]> 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
> <http://10.190.57.71: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:* [email protected] <
> [email protected]> on behalf of David Lee <
> [email protected]>
> *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)
>
>                  } ,
>
>                  <options xmlns="xdmp:eval">
>
>                    <database>{xdmp:database("Ingestion")}</database>
>
>                  </options>
>
>                 )
>
>
>
> 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
> [email protected]
> Phone: +1 812-482-5224
>
> Cell:  +1 812-630-7622
> www.marklogic.com
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Kapoor, Pragya
> *Sent:* Wednesday, October 15, 2014 3:59 AM
> *To:* [email protected]
> *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)
>
>                              ,
>
>                              <options xmlns="xdmp:eval">
>
>
>  <database>{xdmp:database("Ingestion")}</database>
>
>                              </options>
>
>                             )
>
>             for $FileEntry in $DirectoryListing
>
>                 let $Filename :=
> functx:substring-after-last(xdmp:node-uri($FileEntry),'/')
>
>                 let $docUri := fn:concat($PrefixURI, $Filename)
>
>                 let $_ := xdmp:log(fn:concat("uri",$docUri))
>
>                 let $contents := $FileEntry
>
>                 return
>
>                         (: Insert the document :)
>
>                       (dls:document-insert-and-manage(
>
>                        $docUri,
>
>                         fn:false(),
>
>                        $contents,
>
>                         "created",
>
>                         (xdmp:permission("dls-user", "read"),
>
>                          xdmp:permission("dls-user", "update")),
>
>                         "historic"),
>
>                       xdmp:document-add-collections(
>
>                        $docUri,
>
>                         "latest"),
>
>                       xdmp:document-remove-collections(
>
>                             $docUri,  "historic")
>
>
>
>                        )
>
>
>
> "This e-mail and any attachments transmitted with it are for the sole use
> of the intended recipient(s) and may contain confidential , proprietary or
> privileged information. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message. Any unauthorized review, use, disclosure, dissemination,
> forwarding, printing or copying of this e-mail or any action taken in
> reliance on this e-mail is strictly prohibited and may be unlawful."
>   "This e-mail and any attachments transmitted with it are for the sole
> use of the intended recipient(s) and may contain confidential , proprietary
> or privileged information. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message. Any unauthorized review, use, disclosure, dissemination,
> forwarding, printing or copying of this e-mail or any action taken in
> reliance on this e-mail is strictly prohibited and may be unlawful."
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to