Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:21:17+00:00 2026-06-11T02:21:17+00:00

I am currently trying to pull information from the google contacts api. Using the

  • 0

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

$response = json_encode(simplexml_load_string($val->getResponseBody())); 
$result = json_decode($response, true);

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.

$xml = json_encode(simplexml_load_string(null, $val->getResponseBody(), null, 'gd', true));

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:

<gd:extendedProperty xmlns:gs='http://schemas.google_apps_sync.com' name='google_apps_sync'>
    <gs:em_odn1>awalker@xxxxx.com</gs:em_odn1>
    <gs:em_dn1>First Name Last Name</gs:em_dn1>
    <gs:em_ad1>awalker@xxxxxxxxx.com</gs:em_ad1>
    <gs:em_t1>SMTP</gs:em_t1>
    <gs:f_c>32791</gs:f_c>
    <gs:f>Last, First</gs:f>
  </gd:extendedProperty>

EDIT

$xmlResponse = simplexml_load_string($val->getResponseBody(), null, 0, 'gd', true);
$xmlResponse->registerXPATHNamespace('gd', 'http://schemas.google_apps_sync.com');
$xmlResponse->registerXPATHNamespace('gs', 'http://schemas.google_apps_sync.com/contact/2008');

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

$email = json_encode($xmlResponse->xpath('//gd:email'), true));
$postal = json_encode($xmlResponse->xpath('//gd:postalAddress'), true);
$name = json_encode($xmlResponse->xpath('//gs:em_dn1'), true);

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:

json_decode($xmlResponse, true);

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:21:19+00:00Added an answer on June 11, 2026 at 2:21 am

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SAX to pull information from the google weather API and I'm having
I'm currently trying to pull data from a database using a variable and then
Is it possible to pull source data from another domain (not currently owned) using
I'm currently trying to pull GA data using Python; I've gotten as far as
I am trying to pull a value (only) from some XML in Python using
Basically, I'm trying to use the api offered by govtrack.us to pull information and
I'm working on a script currently that needs to pull information down from a
Im currently trying to downlaod a audio track from a WCF, i need some
I am currently trying to write some code that will accept some FTP details,
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.