Hi, Gnanaprakash: Modifying any software distribution raises serious concerns. When the software is updated, you have to reapply your change. In the new updated software, your change may not work. The software vendor may no longer support you because problems can no longer be isolated within the distribution. In short, going into production with a modified distribution is very risky.
The XML sample you gave earlier is a simple structure that maps fairly well to JSON (though even in the sample, it would probably be better if the attribute value were expressed as a JSON number instead of a string), but that's not the case with every XML structure, as the following example shows: xquery version "1.0-ml"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; let $raw := <sample id="123" xmlns="http://some.org/namespace" xmlns:o="http://other.org/namespace"> <title xml:lang="en-us">About <name>Gnana</name> locations</title> <o:address>abc</o:address> </sample> return json:transform-to-json($raw, json:config("custom")) The sample above exhibits only a few of the challenges for transforming from XML to JSON. A transform specific to the XML vocabulary can often do a better job of mapping to JSON than a generic transform, but some XML constructs don't have an equivalent in JSON. The simplification in the design of JSON is deliberate -- after all, if JSON and XML were isomorphic, there wouldn't be much of a case for JSON. One other alternative -- if your REST client has an XML parser, you could just get the search response as XML. Then, the raw XML will be parsed along with the rest of the search response. Hoping that's useful, Erik Hennum ________________________________ From: [email protected] [[email protected]] Sent: Tuesday, December 25, 2012 10:56 PM To: Erik Hennum; [email protected] Subject: RE: Reg Retrieving full document while performing search Hi Erik Hennum, Thanks for detailed explanation about the XML and JSON. Meanwhile, as part of my Rest-API exploration I came across a method where I tweaked the Rest-API code which gave me results as expected. In Rest-API: lib/search-util.xqy Method: sut:serialize-results I customized the code to use JSON conversion instead of returning raw document as it is. I am a bit skeptical about this but as I am handling only raw options this customization seems be a good solution for me. Actual Code: case element() return jsonbld:value(xdmp:quote($raw)) Customized Code: case element() return json:transform-to-json($raw, json:config("custom")) Any thoughts on this? Any ways, I will try exploring other options you mentioned like resource service extensions or XQuery Transformation :) Thanks and Regards, Gnanaprakash Bodireddy Sr Associate - Projects | IME From: Erik Hennum [mailto:[email protected]] Sent: Monday, December 24, 2012 11:52 PM To: Bodireddy, Gnanaprakash (Cognizant); [email protected] Subject: RE: Reg Retrieving full document while performing search Hi, Gnanaprakash: Good to hear you're making progress. XML and JSON have fundamentally different models. Some XML cases have no natural representation in JSON and vice versa. That fundamental mismatch means that there is no standard transform from XML to JSON. (You can search to see some of the alternatives, each of which uses some form of tunnelling for structures that don't fit the JSON model.) As a result, the REST API can only provide out-of-the-box JSON conversion for the XML structures produced directly by MarkLogic. The REST API can't provide JSON conversion for every possible XML document stored in the database. That's a consequence of the XML and JSON mismatch instead of a limitation of MarkLogic. You could write an XSLT or XQuery transform extension to implement the transform from your XML vocabulary to JSON. You could then search to get the document URIs and iterate over the documents to get the transformed documents. Or, you could write a resource services extension that does the search and transform entirely on the server. If you want to work with JSON documents, however, the simplest approach would be to store JSON documents in the database instead of XML documents. Hoping that helps, Erik Hennum ________________________________ From: [email protected]<mailto:[email protected]> [[email protected]] Sent: Monday, December 24, 2012 4:31 AM To: Erik Hennum; [email protected]<mailto:[email protected]> Subject: RE: Reg Retrieving full document while performing search Hi Erik Thanks for the help. I have created the options and it worked fine for me. But I got results which is slightly deviating from my expectation. Options: custom-search <options xmlns="http://marklogic.com/appservices/search"> <transform-results apply="raw"/> </options> URL: http://<<Host>>:9000/v1/search?q=&options=custom-search&format=json<UrlBlockedError.aspx> Result (JSON): { snippet-format: "raw", total: 28252, start: 1, page-length: 10, results: [ { index: 1, uri: "/Test_1.xml", path: "fn:doc("/Test_1.xml")", score: 0, confidence: 0, fitness: 0, content: "<sample id="123"><name>Gnana</name><address>abc</address></sample>" }, { index: 2, uri: "/Test_2.xml", path: "fn:doc("/Test_2.xml")", score: 0, confidence: 0, fitness: 0, content: "<sample id="456"><name>Prakash</name><address>abc</address></sample>" }, ... ] } I am expecting even the content to be shown in JSON. Is there any way I can transform this content node into JSON? Thanks and Regards, Gnanaprakash Bodireddy -----Original Message----- From: Erik Hennum [mailto:[email protected]] Sent: Friday, December 21, 2012 8:08 PM To: Bodireddy, Gnanaprakash (Cognizant) Subject: RE: Reg Retrieving full document while performing search Hi, Gnanaprakash: You don't pass in transform-results as a URI parameter. Instead, you configure query options on the server before you search. To find out how to write query options to the server, please see: http://docs.marklogic.com/guide/rest-dev/search#id_48838 To find out more about the query options supported by the server, please see: http://docs.marklogic.com/guide/search-dev/search-api#id_36346 http://docs.marklogic.com/search:search#opt-transform-results Erik Hennum ________________________________________ From: [email protected]<mailto:[email protected]> [[email protected]] Sent: Friday, December 21, 2012 5:24 AM To: Erik Hennum Subject: RE: Reg Retrieving full document while performing search HI Erik Can you please help me in how I can pass transform-results as options in URL. Do I need to configure anything before passing transform-results? The below one is not working for me. http://<<Host>>:9000/v1/search?q=&format=xml&options=transform-results:raw<UrlBlockedError.aspx> Thanks and Regards, Gnanaprakash Bodireddy >> You can modify your query options to specify transform-results of apply="raw". By the way, you can also use extract-metadata in your query options to get fragments of the result document independent of whether the fragment contained a match on the criteria. Erik Hennum This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful.
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
