JSON to XML(with Cdata in one of field) conversion

I have a scenario, Backend is expecting the SOAP with the CDATA in one of the field and Front end is sending the JSON to the proxy. i have two queries.

1.Does we need to ask the frontend to send the CDATA(in my case value in cdata is XML) in the JSON as a normal string ?

2.How do i convert JSON to XMl with the CDATA field contained in it ?

Solved Solved
0 2 7,026
1 ACCEPTED SOLUTION

Hmmm, well, let's see.

You do not need to ask the front end to send a CDATA in the JSON.

I understand what you said: The backend is expecting a CDATA field. But this is not always required. CDATA is used to "escape" a large area of text that may include characters that are meaningful to XML, like angle brackets. If you have such text, you can use CDATA to wrap it, which tells the XML document processor - "for any text until the end of the CDATA range, ignore the XML-specific characters".

But there is another way to tell the XML processor "ignore the XML-specific characters" - just XML-escape the particular characters. (eg, replace < with & lt; and so on) This works fine. For example:

5629-curl-json-to-xml.png

As you can see, all the xml-sensitive characters are "escaped". (I tried pasting in that string, but I could not get it to display correctly ... the editor here on this forum replaced all the sequences of & lt; with the < symbol, defeating the purpose.)

So I think the JSON-to-XML conversion will just work fine. It may not generate CDATA, but it will be fine anyway. Your backend will not mind. Try it!

I'd like to know your results.

View solution in original post

2 REPLIES 2

Hmmm, well, let's see.

You do not need to ask the front end to send a CDATA in the JSON.

I understand what you said: The backend is expecting a CDATA field. But this is not always required. CDATA is used to "escape" a large area of text that may include characters that are meaningful to XML, like angle brackets. If you have such text, you can use CDATA to wrap it, which tells the XML document processor - "for any text until the end of the CDATA range, ignore the XML-specific characters".

But there is another way to tell the XML processor "ignore the XML-specific characters" - just XML-escape the particular characters. (eg, replace < with & lt; and so on) This works fine. For example:

5629-curl-json-to-xml.png

As you can see, all the xml-sensitive characters are "escaped". (I tried pasting in that string, but I could not get it to display correctly ... the editor here on this forum replaced all the sequences of & lt; with the < symbol, defeating the purpose.)

So I think the JSON-to-XML conversion will just work fine. It may not generate CDATA, but it will be fine anyway. Your backend will not mind. Try it!

I'd like to know your results.

@ Dino : Thanks a lot for the detailed description.let me update you once the backend confirms if the string with escaped characters is fine to it.