Hi Dharmendra,
Thanks for the reply, but didnt work
the Required output is:
{"document-id":"\/docs\/abc.xml", "action":"add", "metadata":[{"name":"XYZ",
"value":"fsddddddddddddddddddddddddddddddd sdgsdsdsdsdsdsdsdsdsdsd",
"type":"text"},{"name":"Period", "value":"aertw hegheh eheheh ghhehe",
"type":"text"}]}
This is a valid json without root.
Thanks
Pragya
________________________________
From: [email protected]
<[email protected]> on behalf of DK Singh
<[email protected]>
Sent: Monday, January 9, 2017 5:44:44 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Json file
Try out the code if it works as your requirement
Regards
Dharmendra Kumar Singh
On Jan 9, 2017 5:34 PM, "DK Singh"
<[email protected]<mailto:[email protected]>> wrote:
Hi Pragya
You can try out the below code:
json:transform-to-json($xml/child::*,$custom)
but your json output won't be valid.
Regards
Dharmendra Kumar Singh
On Mon, Jan 9, 2017 at 5:31 PM, DK Singh
<[email protected]<mailto:[email protected]>> wrote:
Hi Pragya,
You can not remove the element "document" because it is root element either XML
or JSON must have a root element, you can remove the child elements but not the
root element "document". You can replace the element document with other
element.
if you remove the element 'document' your document will not be valid
Regards
Dharmendra Kumar Singh
On Mon, Jan 9, 2017 at 5:08 PM, Kapoor, Pragya
<[email protected]<mailto:[email protected]>> wrote:
Hi,
Now I want to ignore the document element while constructing the json:
import module namespace json = "http://marklogic.com/xdmp/json"
at "/MarkLogic/json/json.xqy";
declare variable $xml :=
<document>
<document-id>/docs/abc.xml</document-id>
<action>add</action>
<metadata>
<name>XYZ</name>
<value>fsddddddddddddddddddddddddddddddd sdgsdsdsdsdsdsdsdsdsdsd</value>
<type>text</type>
</metadata>
<metadata>
<name>Period</name>
<value>aertw hegheh eheheh ghhehe</value>
<type>text</type>
</metadata>
</document> ;
let $custom :=
let $config := json:config("custom")
let $_ := map:put( $config, "whitespace", "ignore" )
let $_ := map:put( $config, "ignore-element-names", "document" )
let $_ := map:put( $config, "array-element-names", "metadata" )
return $config
let $json := json:transform-to-json($xml,$custom)
return $json
But with the above code its not ignoring the document element.
Required output:
{"document-id":"\/docs\/abc.xml", "action":"add", "metadata":[{"name":"XYZ",
"value":"fsddddddddddddddddddddddddddddddd sdgsdsdsdsdsdsdsdsdsdsd",
"type":"text"},{"name":"Period", "value":"aertw hegheh eheheh ghhehe",
"type":"text"}]}
Please let me know, if I am missing something. I am using MarkLogic 7
Thanks
Pragya
________________________________
From:
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>
on behalf of David Lee
<[email protected]<mailto:[email protected]>>
Sent: Tuesday, January 3, 2017 6:39:28 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Json file
In v7 transform-to-json returns a string.
Try xdmp:save("file", text { $json })
-DavId Lee
Sent from my iPad
On Jan 3, 2017, at 5:24 AM, Kapoor, Pragya
<[email protected]<mailto:[email protected]>> wrote:
Hi,
I am getting this error:
XDMP-ARGTYPE: (err:XPTY0004) xdmp:save("C:\123",
"{"document":{"docID":"\/docs\/0000002-0...") -- arg2
is not of type node()
I am using MarkLogic 7.
declare variable $xml :=
<document
docID="/docs/0000002-0000468-0004456-ISDA-COL-XXXX_2015-04-01_06-33-57-639.xml"
action="add">
<metadata>
<name>XYZ</name>
<value>fsddddddddddddddddddddddddddddddd sdgsdsdsdsdsdsdsdsdsdsd</value>
<type>text</type>
</metadata>
<metadata>
<name>Period</name>
<value>aertw hegheh eheheh ghhehe</value>
<type>text</type>
</metadata>
</document>;
let $uri := "123"
let $custom :=
let $config := json:config("custom")
let $_ := map:put( $config, "whitespace", "ignore" )
let $_ := map:put( $config, "array-element-names", "metadata" )
return $config
let $json := json:transform-to-json($xml,$custom)
return
(
xdmp:save(concat('C:\test\', $uri), $json)
)
Thanks
Pragya
________________________________
From:
[email protected]<mailto:[email protected]>
<[email protected]<mailto:[email protected]>>
on behalf of DK Singh <[email protected]<mailto:[email protected]>>
Sent: Monday, January 2, 2017 1:06:24 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Json file
Hi Pragya,
You can try out the below mentioned code:
import module namespace json = "http://marklogic.com/xdmp/json" at
"/MarkLogic/json/json.xqy";
for $xmls in fn:collection('MarcVideo')[1 to 10]
let $xmls1 := xdmp:quote($xmls)
let $xmls2 := xdmp:unquote($xmls1)
let $uri := base-uri($xmls)
let $token := tokenize($uri,'/')[last()]
let $custom :=
let $config := json:config("custom")
let $_ := map:put( $config, "whitespace", "ignore" )
let $_ := map:put( $config, "array-element-names", "Video" )
return $config
let $json := json:transform-to-json($xmls,$custom)
return
(
xdmp:save(concat('D:\test\', $token), $json)
)
Regards
Dharmendra Kumar Singh
On Mon, Jan 2, 2017 at 12:28 PM, Kapoor, Pragya
<[email protected]<mailto:[email protected]>> wrote:
Hi,
Requirement:
1. Convert xmls stored in marklogic db to json then save them to file system.
2. Store in-memory json in ML DB
How can we achieve the same?
Thanks
Pragya
"This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
"This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
"This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
"This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general