Hi David Lee,

I have already tried "full" option for specific nodes.
It worked But, as we don't know which keyword user searches and which element 
will have the highlighted text it will be tough in long run to pass the 
specific element names for "full"

I feel, there should be an option to exclude specified elements from JSON 
conversion.
XML:
 <employee><code>01</code><label>gnana < highlight >prakash</ highlight > 
bodireddy</label></employee>
JSON:
{"employee":{"code":"01", "label":"gnana <highlight>prakash<highlight> 
bodireddy"}}

The reason why I am looking for above solution is as most of the cases after 
performing highlighting, when we are rendering it on UI, we expect to have 
styling defined for highlight element to show the color. By using "full" 
currently we are getting the object as an array which needs additional effort 
to handle array/object as we don't know which element contains the highlighted 
text.

@Erik, I will try looking at your options and will update you if successful.

Gnana

Gnanaprakash Bodireddy | Sr. Associate - Projects | IME | Cognizant Technology 
Solutions.

From: David Lee [mailto:david....@marklogic.com]
Sent: Tuesday, January 29, 2013 9:29 PM
To: MarkLogic Developer Discussion; Bodireddy, Gnanaprakash (Cognizant)
Subject: RE: Custom JSON convertion issue in ML 6

Just an FYI but the "full" JSON strategy can in fact handle mixed text, but is 
very ugly.
As Erik correctly describes mixed text is something JSON was not designed for 
and hence any attempt to force mixed text XML
Into JSON will be ugly ...  As you noticed the "full" conversion preserved 
everything - but its not prety.
As a compromise
You can treat specific nodes as "full"  in the custom conversion like  this:

xquery version "1.0-ml";
import module namespace json="http://marklogic.com/xdmp/json"; at 
"/MarkLogic/json/json.xqy";
let $x := <employee><code>01</code><label>gnana <span>prakash</span> 
bodireddy</label></employee>
let $config := json:config("custom") ,
    $cx := map:put( $config, "whitespace", "ignore" ),
    $cx := map:put( $config , "full-element-names" , "label" )

return json:transform-to-json($x,$config)



{"employee":{"code":"01", "label":{"_children":["gnana 
",{"span":{"_value":"prakash"}}," bodireddy"]}}}





-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
d...@marklogic.com<mailto:d...@marklogic.com>
Phone: +1 650-287-2531
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>

This e-mail and any accompanying attachments are confidential. The information 
is intended solely for the use of the individual to whom it is addressed. Any 
review, disclosure, copying, distribution, or use of this e-mail communication 
by others is strictly prohibited. If you are not the intended recipient, please 
notify us immediately by returning this message to the sender and delete all 
copies. Thank you for your cooperation.

From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [mailto:general-boun...@developer.marklogic.com] On Behalf Of Erik Hennum
Sent: Tuesday, January 29, 2013 10:46 AM
To: 
gnanaprakash.bodire...@cognizant.com<mailto:gnanaprakash.bodire...@cognizant.com>;
 general@developer.marklogic.com<mailto:general@developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] Custom JSON convertion issue in ML 6

Hi, Gnanaprakash:

In XML, annotating part of a flow of text with an element is known as mixed 
content:

    <label>gnana <span>prakash</span> bodireddy</label>

Mixed text is in the design space for XML but not for JSON (which was designed 
for data structures).  In other words, you've run into an impedance mismatch 
between XML and JSON.

Some alternatives:

*  Suppress the entire label if you don't need the label in JSON
*  Convert the entire content of the label to a single text flow if you only 
need the label text.
*  Wrap elements around the text before and after the span to produce a 
DOM-like data structure in JSON.

In 6.x, I think your best strategy for implementing one of those alternatives 
would be to transform the XML using either XSLT or XQuery before converting it 
to JSON.  For instance, here's the documentation for the XQuery approach:

    http://docs.marklogic.com/guide/app-dev/typeswitch#chapter

You can also search for XQuery transformation on the web to find additional 
resources.
Erik Hennum
________________________________
From: 
gnanaprakash.bodire...@cognizant.com<mailto:gnanaprakash.bodire...@cognizant.com>
 [gnanaprakash.bodire...@cognizant.com]
Sent: Tuesday, January 29, 2013 12:34 AM
To: general@developer.marklogic.com<mailto:general@developer.marklogic.com>; 
Erik Hennum
Subject: Custom JSON convertion issue in ML 6
Hi Erik

Not sure whether I can call this as an issue or not. but I am facing an issue 
using custom json conversion

Sample Code:
xquery version "1.0-ml";
import module namespace json="http://marklogic.com/xdmp/json"; at 
"/MarkLogic/json/json.xqy";
let $x := <employee><code>01</code><label>gnana <span>prakash</span> 
bodireddy</label></employee>
let $config := json:config("custom") ,
    $cx := map:put( $config, "whitespace", "ignore" )
let $config-full := json:config("full") ,
    $cx := map:put( $config, "whitespace", "ignore" )
return (json:transform-to-json($x,$config),
        json:transform-to-json($x,$config-full))

Response:
{"employee":{"code":"01", "label":{"_value":" bodireddy", "span":"prakash"}}}
{"employee":{"_children":[{"code":{"_children":["01"]}},{"label":{"_children":["gnana
 ",{"span":{"_children":["prakash"]}}," bodireddy"]}}]}}

In the above response, when used "custom" the leading text value "gnana" is 
missing. How can we get the text?

Note: I am trying to do the json converstion on node with highlighting (with 
span as an element)

Thanks and Regards,

Gnanaprakash Bodireddy

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
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to