0

CDATA to JSON response format

Hi guys,

First let me start off with, if there is a place for (possible) bug reports to be made other than here in the forums would some kind soul please point me in that direction?

Now onto the problem. I have been trying to get YQL to consume some XML and had issues with the JSON output being "wrong" (i.e. not what I thought it should be). After digging around, the issue quickly boiled down to one of mixing CDATA and non-CDATA (or just multiple CDATA) within the same XML node as outlined below.

Example XML

CODE
<?xml version="1.0" encoding="UTF-8"?>
<a>
<b><![CDATA[foo]]>bar</b>
</a>


Example YQL query

CODE
select * from xml where url='http://codepad.org/hYfhEnHt/raw.txt'

Try this in the console

The XML output format is fine (it reflects the CDATA, so all the data is available to me) but the JSON output format only gives the "bar" for that "b" node. Whether the bar is wrapped in another CDATA or not appears to make no difference and indeed the number of different pieces (e.g. CDATA, plain text, CDATA, plaintext) result in the same thing: only the last portion being included in the JSON output.

If this is intended behaviour, do let me know. Either way, in the mean time, it looks like <execute> will have to come to the rescue.

Cheers

by
2 Replies
  • I can see why this could be frustrating. I've run into similar issues myself.

    We use a library to turn XML into JSON however, I'm going to come up with some scenarios to see how we handle these conversations and if we can improve on it.

    Tom
    Yahoo! Developer Network
    0
  • Thanks Tom. If you could ping me if any changes to this ever go live, it would be appreciated. :)
    0

Recent Posts

in YQL