This is my result in xml format how can i convert this into JSON format in salesforce .
(or) is there any other way directly deserialize the XML response.
MyResult == :
<?xml version="1.0" encoding="utf-8"?>
<results>
<status code="ok"/>
<my-events>
<event sco-id="1290617895" type="event" icon="event" permission-id="host">
<name>Adobe connect demo</name>
<domain-name>meet64541292.adobeconnect.com</domain-name>
<url-path>/demo/</url-path>
<date-begin>2017-11-02T19:30:00.000+05:30</date-begin>
<date-end>2017-11-03T18:45:00.000+05:30</date-end>
<expired>true</expired>
<duration>23:15:00.000</duration>
</event>
<event sco-id="1290640959" type="event" icon="event" permission-id="view">
<name>salesforce demo</name>
<domain-name>meet64541292.adobeconnect.com</domain-name>
<url-path>/dmeosfsf/</url-path>
<date-begin>2017-11-02T19:30:00.000+05:30</date-begin>
<date-end>2017-11-02T19:45:00.000+05:30</date-end>
<expired>true</expired>
<duration>00:15:00.000</duration>
</event>
<event sco-id="1290643314" type="event" icon="event" permission-id="view">
<name>Test</name>
<domain-name>meet64541292.adobeconnect.com</domain-name>
<url-path>/testadobe/</url-path>
<date-begin>2017-11-02T18:45:00.000+05:30</date-begin>
<date-end>2017-11-02T20:00:00.000+05:30</date-end>
<expired>true</expired>
<duration>01:15:00.000</duration>
</event>
<event sco-id="1292076280" type="event" icon="event" permission-id="view">
<name>test1</name>
<domain-name>meet64541292.adobeconnect.com</domain-name>
<url-path>/test1/</url-path>
<date-begin>2017-11-08T18:00:00.000+05:30</date-begin>
<date-end>2017-11-08T19:00:00.000+05:30</date-end>
<expired>true</expired>
<duration>01:00:00.000</duration>
</event>
<event sco-id="1292084866" type="event" icon="event" permission-id="host">
<name>TestEvent</name>
<domain-name>meet64541292.adobeconnect.com</domain-name>
<url-path>/testevent/</url-path>
<date-begin>2017-11-08T17:45:00.000+05:30</date-begin>
<date-end>2017-11-09T18:45:00.000+05:30</date-end>
<expired>false</expired>
<duration>1d 01:00:00.000</duration>
</event>
</my-events>
</results>
Best Answer
At this time, Salesforce does not provide a way to automatically transform XML to JSON (nor the other way around).
If you need to do something with XML, you need to write code specifically tailored to that domain (in other words, specific to the structure and data contained in the XML).
There are more than a few questions on this topic, and I'd suggest that you use the search bar on the top of the page to find them. I've even answered a few (1) of (2) them (3) myself (4)
The general approach I take is to use the
Dom.Document
andDom.XmlNode
classes in a series of classes that mimic the schema (structure) of the XML that you're dealing with. This is a 'divide and conquer' type approach. It's a bit of a pain to test, but it keeps the XML that you need to work with in any single method small and manageable.To help you get started...
The above code is only an example to get you started. It will not compile as-is, and you will need to complete it yourself. The point of what I wrote for you is to demonstrate everything you'll need to finish writing it yourself.