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 3311962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:56:17+00:00 2026-05-17T21:56:17+00:00

I am trying to get some data from a GoogleCheckout response. I am using

  • 0

I am trying to get some data from a GoogleCheckout response. I am using a SimpleXmlElement and xpath to search for the data. One of the problems is that the response from xpath is an array of SimpleXmlElements – all I want is the string data. The other is that the response may contain multilpe instances of the TAG name – for example, <email> is shown at least twice but I only want a singe result.

Here is what I have so far

            $notifyData = array();
            $notifyData['buyerEmail'] = $data->xpath('buyer-billing-address//email')[0];
            $notifyData['buyerName'] = $data->xpath('buyer-billing-address//contact-name');
            $notifyData['transactionId'] = $data->xpath('/new-order-notification/google-order-number');
            $notifyData['itemName'] = $data->xpath('//item-name');
            $notifyData['amount'] = $data->xpath('//unit-price');
            $notifyData['currency'] = $notifyData['amount'][0]['currency'];//$data->xpath('//@currency[1]');

here is the response from print_r() on $notifyData

Array
(
    [buyerEmail] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => sandbox@mysite.com
                )

        )

    [buyerName] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => Mr Sandbox Buyer
                )

        )

    [transactionId] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => 271578474675716
                )

        )

    [itemName] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [0] => My Item
                )

        )

    [amount] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [currency] => USD
                        )

                    [0] => 3.99
                )

        )

    [currency] => SimpleXMLElement Object
        (
            [0] => USD
        )

)

What i want is for the data to show like this after print_r()

Array
(
    [buyerEmail] => sandbox@mysite.com
    ...
    [currency] => USD

Here is an example of an xml response

<new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="654578974677716-00001-7">

  <buyer-billing-address>

    <address1>19 sandbox st</address1>

    <address2></address2>

    <phone></phone>

    <email>sandbox@mysite.com</email>

    <company-name></company-name>

    <contact-name>Mr Sandbox Buyer</contact-name>

    <fax></fax>

    <country-code>AU</country-code>

    <city>Buyers Town</city>

    <region>VIC</region>

    <postal-code>3460</postal-code>

  </buyer-billing-address>

  <timestamp>2010-10-24T04:25:41.723Z</timestamp>

  <google-order-number>298578974677716</google-order-number>

  <shopping-cart>

    <items>

      <item>

        <digital-content>

          <key is-encrypted="true">PWWoqHo+FtfTi5vHmquOFTFNb4DwNjInAxkW89PLxtU=</key>

          <description>Follow the instructions</description>

          <url>http://mysite.com</url>

        </digital-content>

        <item-name>my product</item-name>

        <item-description>my product</item-description>

        <unit-price currency="USD">3.99</unit-price>

        <quantity>1</quantity>

      </item>

    </items>

  </shopping-cart>

  <order-adjustment>

    <merchant-codes />

    <total-tax currency="USD">0.0</total-tax>

    <adjustment-total currency="USD">0.0</adjustment-total>

  </order-adjustment>

  <buyer-id>634168749882822</buyer-id>

  <buyer-marketing-preferences>

    <email-allowed>true</email-allowed>

  </buyer-marketing-preferences>

  <buyer-shipping-address>

    <address1>19 sandbox st</address1>

    <address2></address2>

    <phone></phone>

    <email>sandbox@mysite.com</email>

    <company-name></company-name>

    <contact-name>Mr Sandbox Buyer</contact-name>

    <fax></fax>

    <country-code>AU</country-code>

    <city>Buyers Town</city>

    <region>VIC</region>

    <postal-code>3460</postal-code>

  </buyer-shipping-address>

  <order-total currency="USD">3.99</order-total>

  <fulfillment-order-state>NEW</fulfillment-order-state>

  <financial-order-state>REVIEWING</financial-order-state>

</new-order-notification>
  • 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-05-17T21:56:18+00:00Added an answer on May 17, 2026 at 9:56 pm

    You don’t necessarily need xpath here. E.g.

    $notifyData = array(
      'buyerEmail' => (string)$data->{'buyer-billing-address'}->email[0],
      'buyerName' => (string)$data->{'buyer-billing-address'}->{'contact-name'}[0],
      'transactionId' => (string)$data->{'google-order-number'}[0]
    );
    var_dump($notifyData);
    
    
    function getData() {
      return <<< eox
    <new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="654578974677716-00001-7">
    ...
    </new-order-notification>
    eox;
    }
    

    prints

    array(3) {
      ["buyerEmail"]=>
      string(18) "sandbox@mysite.com"
      ["buyerName"]=>
      string(16) "Mr Sandbox Buyer"
      ["transactionId"]=>
      string(15) "298578974677716"
    }
    

    and via foreach you can also handle multiple elements like e.g. <item>

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

Sidebar

Related Questions

I am trying to get some xpath from xsl variable using xsl ver 1.0
I am trying to get some data to display from an Array in Cakephp,
I' trying to get some data from Oracle via ODBC to mySQL database. And
I am trying to get some data from a database on the fly and
I am trying to get some data from the user and send it to
I'm trying to get some data from a datatable in rich:modal panel The whole
I have some code like this trying to get some data from a Documents
I have sugar crm instance and i was trying to get some data from
I am using http://lite.facebook.com And i want to get some data from my account.
I'm trying to get some json data from a remote website. I run my

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.