functions can return sequences to xcc.
try this as a simple example and build on

declare function module:test()
{
    [ 1 to 10 ] ,  "HI" , <node/>
}


----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
d...@epocrates.com<mailto:d...@epocrates.com>
812-482-5224

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Amar Wakkar
Sent: Tuesday, November 15, 2011 5:59 AM
To: general@developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
binary content

Yes it does in an .xqy page or in query console.

Now I am trying to get it to work inside XCC Java code but it does not work as 
it is in AdhocQuery class.

Can we get multiple results out from a module which has this piece of code? 
Function can return just single value so that may not work in this case?


Thanks
Amaresh Wakkar

> From: kelly.stir...@marklogic.com
> To: general@developer.marklogic.com
> Date: Mon, 14 Nov 2011 14:25:05 -0800
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
> This works just fine for me on ML5:
>
> let$d := 
> xdmp:document-get("http://www.gotdogsonline.com/chinese-foo-dog-pictures-breeders-puppies-rescue/pictures-photos/chinese-foo-dog-0001.jpg";)
> return
> xdmp:document-insert("/foo.jpg",$d);
> for $i in collection()
> return ($i/document-uri(.),$i)
>
> -----Original Message-----
> From: general-boun...@developer.marklogic.com 
> [mailto:general-boun...@developer.marklogic.com] On Behalf Of 
> general-requ...@developer.marklogic.com
> Sent: Monday, November 14, 2011 4:28 PM
> To: general@developer.marklogic.com
> Subject: General Digest, Vol 89, Issue 53
>
> Send General mailing list submissions to
> general@developer.marklogic.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://developer.marklogic.com/mailman/listinfo/general
> or, via email, send a message with subject or body 'help' to
> general-requ...@developer.marklogic.com
>
> You can reach the person managing the list at
> general-ow...@developer.marklogic.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of General digest..."
>
>
> Today's Topics:
>
> 1. Re: Retrieving file name/document URI of binary content
> (Amar Wakkar)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 14 Nov 2011 21:27:39 +0000
> From: Amar Wakkar <amar_wak...@hotmail.com>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI
> of binary content
> To: <general@developer.marklogic.com>
> Message-ID: <blu155-w646f3dbc6af6812264e83e8a...@phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
>
> Hello David,
> I tried but no joy...still giving same error about binary nodes not being 
> allowed in element node.
> for $uri in collection("user10")/document-uri(.)return ( $uri , doc($uri) )
> Interestingly, when I created a collection of just text and xml contents both 
> of your suggestions work so the issue is definitely with the binary data and 
> the way it is queried/represented in Marklogic.
> It may sound a silly question, but when I stored a binary image in Marklogic 
> collection along with a document-uri then should there not be some way e.g. 
> Metadata about the resultset which should tell me what is the associated URI 
> for this content when it was stored in Marklogic? It just happened to be a 
> binary image file but should that matter as far as retrieving a document-uri 
> is concerned? It is just a name used to store the data in database, if I can 
> retrieve that name for an XML or TXT file then why not for Binary image?
> ThanksAmaresh Wakkar
> From: d...@epocrates.com
> To: general@developer.marklogic.com
> Date: Mon, 14 Nov 2011 21:09:36 +0000
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
>
>
>
>
>
>
>
>
>
>
> I still dont understand why this doesnt work:
>
> for $x in collection("user10")
> return
> ( fn:document-uri($x) , $x )
>
>
> But you can always try
>
>
> for $uri in
> collection("user10")/document-uri(.)
> return ( $uri , doc($uri) )
>
>
> ----------------------------------------
> David A. Lee
> Senior Principal Software Engineer
> Epocrates, Inc.
> d...@epocrates.com
> 812-482-5224
>
>
>
>
> From: general-boun...@developer.marklogic.com 
> [mailto:general-boun...@developer.marklogic.com]
> On Behalf Of Amar Wakkar
>
> Sent: Monday, November 14, 2011 3:53 PM
>
> To: general@developer.marklogic.com
>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
>
>
>
>
> Thanks!!!
>
>
>
>
>
> The dot definitely made the difference.. I can now query the content and 
> document-uri in separate queries, but it would have been great if I could
> just fetch them together in single query like other experts pointed out:
>
>
>
>
>
> More importantly, if I query these two separately, is there a guarantee that 
> they will come in correct order everytime? I mean the image name at position
> 1 will always correspond to image-1 retrieved in a separate query for that 
> collection?
>
>
>
>
>
> If it all was fetched in single query then these issues would not have come, 
> is it not?
>
>
>
>
>
> Of course there is one way to do it i.e. a nested query. Get the file 
> names/document-uris and then get the documents but that will be more than 2
> calls to Marklogic, I think.
>
>
>
>
>
> Thanks
>
>
>
>
>
> Amaresh
>
>
>
>
>
>
>
>
> From: seme...@hotmail.com
>
> To: general@developer.marklogic.com
>
> Date: Mon, 14 Nov 2011 12:58:41 -0700
>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
>
> Try this:
>
>
>
> Request request = session.newAdhocQuery(" 
> collection('imageCollection')/document-uri(.) ");
>
>
>
> notice the dot in the document-uri() function
>
>
>
>
>
>
> From: d...@epocrates.com
>
> To: general@developer.marklogic.com
>
> Date: Mon, 14 Nov 2011 19:58:07 +0000
>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
> You can return them as pairs in a sequence
>
> for $x in collection("user10")
> return
> ( fn:document-uri($x) , $x )
>
> Not sure why the XCC code isnt returning the document-uri but it might not 
> know it )
>
>
> ----------------------------------------
> David A. Lee
> Senior Principal Software Engineer
> Epocrates, Inc.
> d...@epocrates.com
> 812-482-5224
>
>
>
>
> From: general-boun...@developer.marklogic.com 
> [mailto:general-boun...@developer.marklogic.com]
> On Behalf Of Amar Wakkar
>
> Sent: Monday, November 14, 2011 2:42 PM
>
> To: general@developer.marklogic.com
>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
>
>
>
> Hello David,
>
>
>
>
> No luck, I am getting following error when I try your suggestion:
>
>
>
>
>
>
> com.marklogic.xcc.exceptions.XQueryException: XDMP-TOOFEWARGS: (err:XPST0017) 
> fn
>
>
> :document-uri() -- Too few args, expected 1 but got 0
>
>
> [Session: user=user, cb=XCCTestDB [ContentSource: user=user, cb=XCCTestDB 
> [prov
>
>
> ider: address=localhost/127.0.0.1:8006, pool=1/64]]]
>
>
> [Client: XCC/4.2-7, Server: XDBC/5.0-1]
>
>
> in /eval, on line 1
>
>
> expr: fn:document-uri()
>
>
> at com.marklogic.xcc.impl.handlers.ServerExceptionHandler.handleResponse
>
>
> (ServerExceptionHandler.java:30)
>
>
> at com.marklogic.xcc.impl.handlers.EvalRequestController.serverDialog(Ev
>
>
> alRequestController.java:78)
>
>
> at com.marklogic.xcc.impl.handlers.AbstractRequestController.runRequest(
>
>
> AbstractRequestController.java:78)
>
>
> at com.marklogic.xcc.impl.SessionImpl.submitRequest(SessionImpl.java:268
>
>
> )
>
>
>
>
>
> Basically I want to be able to get images stored in Marklogic server back on 
> a JSP page in an <img> tag. So far, I can get the html content upto
> the JSP page, however to render image, I want to be able to use the same name 
> used while storing the image in Marklogic database e.g. image1,2,3 etc as 
> document URI.
>
>
>
>
>
> I tried following in QConsole which works but there are two problems with it:
>
>
> for $x in collection("user10")
>
>
> return
>
>
> fn:document-uri($x)
>
>
>
>
>
> Problem:1 :
>
>
> It retrieves only the file names so I will have to write one query to get the 
> content and other query to get the file names, that does not sound
> quite right.
>
>
>
>
>
> Problem:2:
>
>
> Even if problem-1 is not an issue, how do I get it to work from Java code? 
> Should I copy these lines in a .xqy module/page and invoke it somehow
> from JSP?
>
>
>
>
>
>
>
>
> Is there any better way to get image and it's document-uri in one go from 
> Marklogic. I stored them as binary instances when creating content. I am
> using Marklogic-5.
>
>
>
>
>
> Thanks
>
>
> Amaresh Wakkar
>
>
>
>
>
>
>
>
>
>
>
>
>
> From: d...@epocrates.com
>
> To: general@developer.marklogic.com
>
> Date: Mon, 14 Nov 2011 15:08:19 +0000
>
> Subject: Re: [MarkLogic Dev General] Retrieving file name/document URI of 
> binary content
>
> Try this:
>
> Request request = session.newAdhocQuery(" 
> collection('imageCollection')/document-uri() ");
>
>
>
>
> ----------------------------------------
> David A. Lee
> Senior Principal Software Engineer
> Epocrates, Inc.
> d...@epocrates.com
> 812-482-5224
>
>
>
>
> From: general-boun...@developer.marklogic.com 
> [mailto:general-boun...@developer.marklogic.com]
> On Behalf Of Amar Wakkar
>
> Sent: Monday, November 14, 2011 9:27 AM
>
> To: general@developer.marklogic.com
>
> Subject: [MarkLogic Dev General] Retrieving file name/document URI of binary 
> content
>
>
>
>
> Dear all,
>
>
>
>
> I am learning ways of doing things in Marklogic server. I have managed to 
> save a collection to Marklogic server which consists of few .gif images.
> The document URI's are the actual file names when I stored them in collection 
> e.g. image1, image2 etc..The collection is named "imageCollection". I can 
> query for "imageCollection" and it does return 3 images in result set. 
> Unfortunately, I am unable to figure
> out how to get "file name" or Document URI of these images ?
>
>
>
>
>
>
>
>
>
> createOptions = ContentCreateOptions.newBinaryInstance();
>
>
>
> createOptions.setCollections(new String[]{"imageCollection"});
>
>
>
>
>
>
>
> createOptions.setFormatBinary();
>
>
>
>
>
>
> content = ContentFactory.newContent(someContent.getAttachmentsFileNames()[i], 
> someContent.getAttachments()[i], createOptions);
>
>
> System.out.println("Inserting contents..");
>
>
> session.insertContent(content);
>
>
>
>
>
>
>
>
> The call to
>
>
>
>
>
>
> Request request = session.newAdhocQuery(" collection(\"imageCollection\") ");
>
>
>
>
>
>
>
> ResultSequence rs = session.submitRequest(request);
>
>
>
>
>
>
>
> while(rs.hasNext()){
>
>
>
> System.out.println("Inside contentDao 44444444");
>
>
>
>
>
>
> ResultItem item = rs.next();
>
>
>
>
>
>
>
>
> Following call returns null
>
>
> System.out.println(item.getDocumentURI());
>
>
>
>
>
> Please help me understand how to get the file names of the images so that I 
> can use them to render back on screen.
>
>
>
>
>
>
>
>
> Thanks
>
>
> Amaresh Wakkar
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________ 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
>
>
>
>
> _______________________________________________ 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
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> http://developer.marklogic.com/pipermail/general/attachments/20111114/b2bc2223/attachment.html
>
> ------------------------------
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
> End of General Digest, Vol 89, Issue 53
> ***************************************
> _______________________________________________
> 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

Reply via email to