4 ms·
Not a parse error but a single “result” object, not an array of length 1. With two elements it recognizes an array.
by Ididntdothis 7y ago
Not a parse error but a single “result” object, not an array of length 1. With two elements it recognizes an array.
- thaumasiotes 7y agoIf you can parse <results> <result></result> </results> and you end up with a single "result" object, you must have identified "results" as being an array of one element so that you could discard it. (You didn't get a single "results" object.) That's not a problem in what XML is able to model, it's a problem with you throwing the information you got away and then pretending you didn't receive it. On the other hand, if you meant that you get a single "results" object, then you're saying that your code is written to require invalid XML and fall down when valid XML is provided. Again, that sounds more like a problem with your code than with the modeling capabilities of XML. There's an argument to be made for accepting invalid input; rejecting valid input is ridiculous.
- vaidhy 7y agoYou do understand that php and quite a few other languages provide pre-built serialization and de-serialization from XML, right? The OP was talking about the out of box behaviour for those. Your answer seems to predicate on having written a custom deserializer.
- thaumasiotes 7y agoMy answer is predicated on the idea that you should be using a deserializer that doesn't rely on receiving invalid input, regardless of whether that deserializer comes from a standard library.