-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug or feature? XML reply with 1 entry behaves differently with n entries #21
Comments
The parser has no way of telling whether a value is meant to be an array unless it has multiple elements with the same names in the XML document. The workaround (if you haven't found it already) is to cast the value to an array when you retrieve it: $responseItems = (array) $requestStatus->parsedResponse['GetFeedSubmissionListResult']['FeedSubmissionInfo']; |
I haven't found a sensible solution to this. Casting to an array is pointless if there is more than one element in the child node, because it already is itself an array. @andreasba - I know your post was a long time ago but did you find a workaround? |
The only workaround I could think about is testing it yourself: $responseItems = $requestStatus->parsedResponse['GetFeedSubmissionListResult']['FeedSubmissionInfo'];
if(!isset($responseItems[0])) {
$responseItems[0] = $responseItems;
} |
Here is my workaround. Not sure how safe this is, but it's working for the cases I've tested.
For the example in the OP, call it like:
You can then (fairly) safely...
|
@wallacio - the workarounds above are pretty similar to mine :) |
@andreasba I would bet that there isn't another option. :/ |
Good morning,
I am not sure whether this is a bug or a feature or if I am using Parser in a wrong way.
Take the following XML:
If I parse this using
my $responseItems contain an array of four items from $responseItems[0] to $responseItems[3] where I can access all attributes like FeedSubmissionId for example like $responseItems[1]['FeedSubmissionId'] - perfect.
However, if the XML response only has ONE FeedSubmissionInfo item, like this:
Then $responseItems[0]['FeedSubmissionId'] throws an illegal offset error, since the parser (of course?) parsed the response not like $responseItems[0]['FeedSubmissionId'] but like this: $responseItems['FeedSubmissionId'].
Now I am wondering if this is a bug or works as designed?
And what would be the workaround? Convert the whole xml to a collection and then work with that?
Thanks
Andreas
The text was updated successfully, but these errors were encountered: