Is it supposed to be possible to transmit arbitrary nested data structures in the API? Or do the format serializers make some assumptions that limit what we can do?
I added a change yesterday which returns a complex parse tree via the API. It works fine in JSON format, but in XML (depending on how I do it) I either get empty elements, or I get Sanitizer warnings. I was using the addPageSubItem() method, inherited from ApiQueryBase.
Some more details are in this bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=34058
On Tue, Jan 31, 2012 at 5:01 PM, Neil Kandalgaonkar neilk@wikimedia.org wrote:
Is it supposed to be possible to transmit arbitrary nested data structures in the API? Or do the format serializers make some assumptions that limit what we can do?
I added a change yesterday which returns a complex parse tree via the API. It works fine in JSON format, but in XML (depending on how I do it) I either get empty elements, or I get Sanitizer warnings. I was using the addPageSubItem() method, inherited from ApiQueryBase.
I wish I could go back in time to 2006 and warn Yuri that supporting XML in the API was a really bad idea. I hate having to continue support for XML because it limits the keys you can use in all sorts of ways.
I can't tell you exactly what's going wrong unless you can give me a full dump of the relevant PHP data structure that you tried to run through the XML formatter. You may or may not be able to get away with some indexed tag names here and there.
(Also, are you sure you really want to support WikiDOM being formatted as XML or WDDX or ... ?)
Roan
On 1/31/12 8:06 AM, Roan Kattouw wrote:
I hate having to continue support for XML because it limits the keys you can use in all sorts of ways.
Right. I'm assuming here that the XML serializer makes some assumptions about arrays and so on and how to transform them into nested tags. Which are failing.
I can't tell you exactly what's going wrong unless you can give me a full dump of the relevant PHP data structure
Please avoid solutions where your presence is required to solve a problem.
that you tried to run through the XML formatter. You may or may not be able to get away with some indexed tag names here and there.
Wikidom is still a moving target. Let's just assume it has to be an arbitrary data structure. And one that I'd rather not have to update the API for every time we change it.
(Also, are you sure you really want to support WikiDOM being formatted as XML or WDDX or ... ?)
Probably not. The other option is to stringify it, as the API sometimes does with returned XML.
But then you have quoted JSON in JSON, and that seems stupid too.
On Tue, Jan 31, 2012 at 6:10 PM, Neil Kandalgaonkar neilk@wikimedia.org wrote:
On 1/31/12 8:06 AM, Roan Kattouw wrote:
I hate having to continue support for XML because it limits the keys you can use in all sorts of ways.
Right. I'm assuming here that the XML serializer makes some assumptions about arrays and so on and how to transform them into nested tags. Which are failing.
Yes. Specifically, you will get broken XML output if you specify invalid keys (like keys with spaces), and you'll get an exception if you have arrays with numerical keys without having set an indexed tag name...
I can't tell you exactly what's going wrong unless you can give me a full dump of the relevant PHP data structure
Please avoid solutions where your presence is required to solve a problem.
...but the error you reported is something I've never seen before, so I'm offering to debug it based on the provided input.
Wikidom is still a moving target. Let's just assume it has to be an arbitrary data structure. And one that I'd rather not have to update the API for every time we change it.
As long as the keys are reasonable (i.e. are valid as XML tags and attributes), you'll be fine with some indexed tag name mangling. But the error message you got suggests you gave it something very weird.
Maybe you gave it an object instead of an array, because you forgot to pass true as the second argument to json_decode()/FormatJson::decode() ?
Probably not. The other option is to stringify it, as the API sometimes does with returned XML.
But then you have quoted JSON in JSON, and that seems stupid too.
Yeah, JSON stringification is probably the sanest thing to do, but yeah the JSON-in-JSON thing is stupid.
Roan
wikitech-l@lists.wikimedia.org