And to answer your previous question about documentation of these constructors, Santhosh, the MarkLogic Server XQuery Reference Guide (http://developer.marklogic.com/pubs/4.1/books/xquery.pdf) mentions the binary constructor in the "MarkLogic Server Enhanced XQuery Language" chapter. The XQuery standard constructors are described in the "XQuery Language" chapter and in the W3C XQuery recommendation (http://www.w3.org/TR/xquery/#id-computedConstructors).
-Danny -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Geert Josten Sent: Tuesday, September 08, 2009 8:31 AM To: General Mark Logic Developer Discussion Subject: RE: [MarkLogic Dev General] How to insert binary or text documentusing xdmp:document-insert() function - reg., Hi Santhosh, The "deadbeef" works because it is a string that can be casted to xs:hexBinary, in other words it is a string containing only digits or characters a-f. Converting plain text to binary requires converting each character to its hexadecimal representation. You can do that as follows: binary { string-join(xdmp:integer-to-hex(string-to-codepoints("Testing binary Constructor")), "") } But if you are really storing plain text, you could store that as a text node just as well.. ;-) Kind regards, Geert > Drs. G.P.H. Josten Consultant http://www.daidalos.nl/ Daidalos BV Source of Innovation Hoekeindsehof 1-4 2665 JZ Bleiswijk Tel.: +31 (0) 10 850 1200 Fax: +31 (0) 10 850 1199 http://www.daidalos.nl/ KvK 27164984 De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. > From: [email protected] > [mailto:[email protected]] On Behalf Of > Santhosh Raj > Sent: dinsdag 8 september 2009 16:53 > To: General Mark Logic Developer Discussion > Subject: RE: [MarkLogic Dev General] How to insert binary or > text document using xdmp:document-insert() function - reg., > > > Hi Danny, > > The binary constructor which you provided is working > fine. But when i change the content "deadbeef" with some > other value, It is giving Invalid Cast error. > > Eg: If I use > > xquery version "1.0-ml"; > try { > xdmp:document-insert("abc.doc", binary { "Testing binary > Constructor" } ) } catch ($e) { > $e > } > > Error: > <error:code>XDMP-CAST</error:code> > <error:name>err:FORG0001</error:name> > <error:xquery-version>1.0-ml</error:xquery-version> > <error:message>Invalid cast</error:message> > <error:format-string>XDMP-CAST: (err:FORG0001) binary { > "Testing binary Constructor" } -- Invalid cast: "Testing > binary Constructor" cast as xs:hexBinary</error:format-string> > <error:retryable>false</error:retryable> > <error:expr>binary { "Testing binary Constructor" }</error:expr> > > When I just copy paste whatever you have sent then it is working. > xquery version "1.0-ml"; > xdmp:document-insert("notxml.xml", binary { "deadbeef" } ); > xdmp:node-kind(doc("notxml.xml")/node()) > => binary > > Please let me know what to do in this regard. > > Thanks and Regards, > Santhosh Rajasekaran > Tata Consultancy Services > Mailto: [email protected] > Website: http://www.tcs.com <http://www.tcs.com/> > ____________________________________________ > Experience certainty. IT Services > Business Solutions > Outsourcing > ____________________________________________ > > > > From: Danny Sokolsky <[email protected]> > To: General Mark Logic Developer Discussion > <[email protected]> > Date: 09/04/2009 10:07 PM > Subject: RE: [MarkLogic Dev General] How to insert > binary or text document using xdmp:document-insert() > function - reg., > Sent by: [email protected] > > ________________________________ > > > > > You can use the text { } or binary { } or node constructors. > xdmp:document-insert will load the document according to the > node kind of the 2nd parameter. For example, to store a text > file with uri "notxml.xml", try something like this: > > xquery version "1.0-ml"; > xdmp:document-insert("notxml.xml", text { "This is a text node." } ); > xdmp:node-kind(doc("notxml.xml")/node()) > => text > > xquery version "1.0-ml"; > xdmp:document-insert("notxml.xml", binary { "deadbeef" } ); > xdmp:node-kind(doc("notxml.xml")/node()) > => binary > > -Danny > > From: [email protected] > [mailto:[email protected] > <mailto:[email protected]> ] On Behalf > Of Santhosh Raj > Sent: Friday, September 04, 2009 7:46 AM > To: [email protected] > Subject: [MarkLogic Dev General] How to insert binary or text > document using xdmp:document-insert() function - reg., > > > Hi all, > > I have to store .txt or .doc,.pdf files in marklogic > server using xdmp:document-insert() function. > > In the Marklogic built-in functions it is represented as following: > > xdmp:document-insert( > $uri as xs:string, > $root as node(), > [$permissions as element(sec:permission)*], > [$collections as xs:string*], > [$quality as xs:int?], > [$forest-ids as xs:unsignedLong*] > ) as empty-sequence() > > > $root : The root node. The root node can be one of XML > format, binary (BLOB) format, or text (CLOB) format. > > Eg: If i want to store a .txt file (sample.txt) with content > as "This is a sample text document." > or > If i want to store a .doc file (sample.doc) with > content as "This is a sample word document" > > then how do i construct the root node of binary(BLOB) format > or text(CLOB) format. > > How can i insert the document(text/doc) to database. > > > Thanks and Regards, > Santhosh Rajasekaran > =====-----=====-----===== > Notice: The information contained in this e-mail > message and/or attachments to it may contain > confidential or privileged information. If you are > not the intended recipient, any dissemination, use, > review, distribution, printing or copying of the > information contained in this e-mail message > and/or attachments to it are strictly prohibited. If > you have received this communication in error, > please notify us by reply e-mail or telephone and > immediately and permanently delete the message > and any attachments. Thank you > > > _______________________________________________ > General mailing list > [email protected] > http://xqzone.com/mailman/listinfo/general > <http://xqzone.com/mailman/listinfo/general> > > > > =====-----=====-----===== > Notice: The information contained in this e-mail > message and/or attachments to it may contain > confidential or privileged information. If you are > not the intended recipient, any dissemination, use, > review, distribution, printing or copying of the > information contained in this e-mail message > and/or attachments to it are strictly prohibited. If > you have received this communication in error, > please notify us by reply e-mail or telephone and > immediately and permanently delete the message > and any attachments. Thank you > > > _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
