[MarkLogic Dev General] json:transform-to-json() with custom configuration is suppressing some content in XML to JSON transformation

David Lee David.Lee at marklogic.com
Sat Jan 2 10:24:51 PST 2016


The custom strategy will not work on arbitrary content.
The 'full' strategy will.

https://docs.marklogic.com/json:config

At the expense of much more verbose and 'ugly' Markup.

You can specify a set of names in the custom strategy to format as full
See:

full-element-names


A list of XML element names which will be treated as an full expansion in JSON similar to the full strategy. These can be xs:QName or xs:string. If an xs:string is used then the default namespace is used to construct the QName.




Another approach is to preprocessing the XML into a form that that
Eliminates mixed text and repeated element children

Similarly the resultant. JSON, if it is full fidelity , can be post processed
To your final desired form




Sent from my iPad
David A Lee
dlee at marklogic.com<mailto:dlee at marklogic.com>


On Jan 2, 2016, at 1:15 PM, Indrajeet Verma <indrajeet.verma at gmail.com<mailto:indrajeet.verma at gmail.com>> wrote:

Hi,

I am using json:transform-to-json() function to convert XML node to json however for a nested xml node and with custom configuration, this function is suppressing some content.

Could you please suggest where I am doing mistake or this is not the right conversion (json is not fit for mixed content )?

import module namespace json = "http://marklogic.com/xdmp/json"
    at "/MarkLogic/json/json.xqy";

let $node := <p>This is my test data <i>this should be italic</i> sample content</p>
let $custom :=
    let $config := json:config("custom")
    let $_ := map:put( $config, "whitespace", "ignore" )
    return $config
  return
    json:transform-to-json( $node, $custom )


Result-

{
"p":
{
"i": "this should be italic",
"_value": " sample content"
}
}


import module namespace json = "http://marklogic.com/xdmp/json"
    at "/MarkLogic/json/json.xqy";

let $node := <p>This is my test data <i>this should be italic</i> sample content</p>
return
    json:transform-to-json( $node, json:config("full") )

Result-

{
"p":
{
"_children":
[
"This is my test data ",
{
"i":
{
"_children":
[
"this should be italic"
]
}
}
,
" sample content"
]
}
}

Regards,
Indrajeet
_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20160102/18930e57/attachment-0001.html 


More information about the General mailing list