Preprocess your XML so that the part you want left as a String in JSON is 
really string not XML.
JSON doesn't know XML so cant just embed it in JSON without encoding it 
properly.
use xdmp:quote() to turn an xml node into a string.


ex: (simplified)

let $html-part := <table><tr><td>cell</td></tr></table>
let $to-transform :=
  <document>
    <item>
        <description>{ xdmp:quote($html-part) }</description>
    </item>
   </document>

return json:transform-to-json( $to-transform )





From: [email protected] 
[mailto:[email protected]] On Behalf Of Kapoor, Pragya
Sent: Tuesday, January 10, 2017 5:29 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: [MarkLogic Dev General] XML to JSON


Hi,



My XML is like

<document>
<document-id>
/docs/abc.xml
</document-id>
<action>
add
</action>
<metadata>
<name>
ID
</name>
<type>
text
</type>
<value>12345</value>
</metadata>
<metadata>
<name>
Eligible
</name>
<type>
text
</type>
<value>
<table>
<tr>
<td>
<p/>
</td>
<td>
<p/>
</td>
<td>
<p>
Valuation Percentage
</p>
</td>
</tr>
<tr>
<td>
<p>
(A)
</p>
</td>
<td>
<p>
Cash in an Currency
</p>
</td>
<td>
<p>
<span class="decimal">
100%
</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
(B)
</p>
</td>
<td>
<p>
Other parties
</p>
</td>
<td>
<p>
As agreed
</p>
</td>
</tr>
</table>
</value>
</metadata>
</document>



Now I want  to convert the xml into json but the ouptut should be like

.....

...

{

"metadata": [

{

"name": "DocumentFamilyID",

"type": "text",

"value": "<documentfamilyhash>"

},

{

"name": "Collateral",

"type": "text",

"value": "<table>
<tr>
<td>
<p/>
</td>
<td>
<p/>
</td>
<td>
<p>
Valuation Percentage
</p>
</td>
</tr>
<tr>
<td>
<p>
(A)
</p>
</td>
<td>
<p>
Cash in an Currency
</p>
</td>
<td>
<p>
<span class="decimal">
100%
</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
(B)
</p>
</td>
<td>
<p>
Other parties
</p>
</td>
<td>
<p>
As agreed
</p>
</td>
</tr>
</table>"

},

]

}



So, I donot want to convert the table element into json.

I tired using ignore-element-names, but is converting the table data into 
text,I want the table to be not converted into json or text.



Is this possible in ML 7.



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]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to