Skip to content
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

Parsed XML returns empty array #23

Closed
cdgn-coding opened this issue Feb 24, 2016 · 1 comment
Closed

Parsed XML returns empty array #23

cdgn-coding opened this issue Feb 24, 2016 · 1 comment

Comments

@cdgn-coding
Copy link

I'm getting this XML from an API call,

<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> 
  <cas:authenticationFailure code='INVALID_TICKET'> ticket 'ST-29070-02O0Y6LAcOmMC9ytvddU-cas' not recognized </cas:authenticationFailure> 
</cas:serviceResponse>

When I do

$xml = \Parser::xml( $response->getBody() );
dd($xml);

I just get an ampty array: []

Wondering the cause

@danhunsaker
Copy link
Contributor

The XML parser uses SimpleXML to read in the XML data, the does a JSON encode/decode to convert it to a simple array, cleaning up a few special cases in the process. This silently discards namespaced elements, due to how SimpleXML handles array conversion. More detail is available in the PHP docs, though the comment in question is a bit of a rant about how the author thinks this is a bad approach in general.

Short answer: namespaced XML isn't supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants