Skip to content
Advertisement

simplexml_load_string correct parameters for namespace

I am currently trying to pull information from the google contacts api. Using the sample code provided in the libraries:

JavaScript

the simplexml_load_string function does not pick up on namespaces. Looking at php.net and how to add the parameters I am a little lost.

JavaScript

event with trying to pull the ‘gd’ namespace from my xml string I am receiving an error. Is there anyone who can assist in this?

The output error is this:

simplexml_load_string() expects parameter 2 to be a class name derived from SimpleXMLElement

But on top of this error it also correctly prints the info I want…I am confused.

Example of info I need to pull:

JavaScript

EDIT

JavaScript

The above code allows me to access the namespaces that I need, but only one at a time….for instance:

JavaScript

if I print these variables I get the respective information I need, but is there not a way for me to access the original $xmlResponse variable after I have initiated the namespaces that I want?

ex:

JavaScript

Won’t give me the xml information with the namespaces I have defined.

Advertisement

Answer

I found after hours of combing info on stackoverflow and relatively undocumented on google… if you add ?alt=json to the end of your contacts api uri you will receive the response in JSON!

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement