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: [email protected]
[[email protected]]
Sent: Tuesday, January 29, 2013 12:34 AM
To: [email protected]; 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.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general