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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:14+00:00 2026-05-23T11:49:14+00:00

I’m trying to work with LINQ to XML to parse the notifications I’m getting

  • 0

I’m trying to work with LINQ to XML to parse the notifications I’m getting from Google Checkout.

The response is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="153286076708098-00005-6">
 <authorization-amount currency="USD">60.0</authorization-amount>
 <authorization-expiration-date>2011-07-03T21:27:48.000Z</authorization-expiration-date>
 <avs-response>Y</avs-response>
 <cvn-response>M</cvn-response>
 <timestamp>2011-06-26T21:28:48.741Z</timestamp>
 <google-order-number>153286076708098</google-order-number>
 <order-summary>
   <total-chargeback-amount currency="USD">0.0</total-chargeback-amount>
   <google-order-number>153286076708098</google-order-number>
   <total-charge-amount currency="USD">0.0</total-charge-amount>
   <total-refund-amount currency="USD">0.0</total-refund-amount>
   <risk-information>
     <ip-address>77.42.229.34</ip-address>
     <billing-address>
       <address1>somewhere in Beirut</address1>
       <address2></address2>
       <phone>70892555</phone>
       <email>Technical@fisharwe.com</email>
       <contact-name>Fisharwe User</contact-name>
       <company-name></company-name>
       <fax></fax>
       <country-code>LB</country-code>
       <city>Beirut</city>
       <region></region>
       <postal-code>1000</postal-code>
     </billing-address>
     <avs-response>Y</avs-response>
     <cvn-response>M</cvn-response>
     <eligible-for-protection>true</eligible-for-protection>
     <partial-cc-number>1111</partial-cc-number>
     <buyer-account-age>18</buyer-account-age>
   </risk-information>
   <authorization>
     <authorization-amount currency="USD">60.0</authorization-amount>
     <authorization-expiration-date>2011-07-03T21:27:48.000Z</authorization-expiration-date>
   </authorization>
   <purchase-date>2011-06-26T21:27:48.000Z</purchase-date>
   <archived>false</archived>
   <shopping-cart>
     <items>
       <item>
         <item-name>Credits</item-name>
         <item-description>Description</item-description>
         <unit-price currency="USD">60.0</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>
   <promotions />
   <buyer-id>975104325298289</buyer-id>
   <buyer-marketing-preferences>
     <email-allowed>false</email-allowed>
   </buyer-marketing-preferences>
   <buyer-shipping-address>
     <address1>somewhere in Beirut</address1>
     <address2></address2>
     <phone>70892555</phone>
     <email>Technical@fisharwe.com</email>
     <contact-name>Fisharwe User</contact-name>
     <company-name></company-name>
     <fax></fax>
     <structured-name>
       <first-name>Fisharwe</first-name>
       <last-name>User</last-name>
     </structured-name>
     <country-code>LB</country-code>
     <city>Beirut</city>
     <region></region>
     <postal-code>1000</postal-code>
   </buyer-shipping-address>
   <order-total currency="USD">60.0</order-total>
   <fulfillment-order-state>NEW</fulfillment-order-state>
   <financial-order-state>CHARGEABLE</financial-order-state>
 </order-summary>
</authorization-amount-notification>

Here’s the code I’m using:

        var serverResponse = _checkoutService.Post(data, GoogleCheckoutConstants.ReportsUri);
        var xmlData = XDocument.Parse(serverResponse);
        bool charged = false;
        if(xmlData.Root.Name.Equals("authorization-amount-notification"))
        {

            var amount = (from c in xmlData.Elements()
                          where c.Name.Equals("authorization-amount")
                          select c).First().Value;
            var googleNumber = (from c in xmlData.Elements()
                                where c.Name.Equals("google-order-number")
                                select c).First().Value;
            _checkoutService.ChargeAndShip(googleNumber, amount);
            charged = true;
        }

This is the first time I use LINQ to XML, so I’m not really sure what’s wrong with my code. But it’s not even going inside the if statement. So when I replace the condition with:

if (serverResponse.IndexOf("authorization-amount-notification") > -1)

I end up getting errors telling me that the amount and googleNumber were not found.

Any suggestions?

  • 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-23T11:49:15+00:00Added an answer on May 23, 2026 at 11:49 am

    You need to put the namespace in to the Xml, and you the Elements are SubElements of the Root Node.

    You are only after one Element so doing Elements() then .First() is pointless. Just do Element() instead.

    Also, you can match element names by passing in the Name of the Element + namespace to the Element() method.

    var xmlData = XDocument.Parse(xml);
    
    XNamespace ns = "http://checkout.google.com/schema/2";
    
    if (xmlData.Root.Name == ns + "authorization-amount-notification")
    { 
        var amount = 
            xmlData
            .Root
            .Element(ns + "authorization-amount")
            .Value;
    
        var googleNumber = 
            xmlData
            .Root
            .Element(ns + "google-order-number")
            .Value;  
        _checkoutService.ChargeAndShip(googleNumber, amount);             
    
        charged = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.