Been working a lot with Google Checkout and the responses are always huge amount of XML data. What i want is to parse out the node called merchant-private-data from this rubble.
It might not always be present and it might be on several positions (with the same value).
I tried a simple approach but that did not yield any results.
From the sandbox response:
<?xml version="1.0" encoding="UTF-8"?>
<authorization-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="123456789">
<authorization-amount currency="USD">11.65</authorization-amount>
<authorization-expiration-date>2012-08-21T12:30:16.000Z</authorization-expiration-date>
<avs-response>Y</avs-response>
<cvn-response>U</cvn-response>
...
<order-summary>
...
<shopping-cart>
...
<merchant-private-data>
<MERCHANT_DATA_HIDDEN>50c77071-aeea-40fe-962b-f4d51d1f9b0</MERCHANT_DATA_HIDDEN>
</merchant-private-data>
...
</shopping-cart>
...
</order-summary>
</authorization-amount-notification>
Might be in more locations and might not always be in that location.
My idea was this, but it did not work (yields 0 results even though i can see the node in the xml):
XDocument input = XDocument.Parse(xmldata);
string privateData = null;
var privateDataNode = (from nodes in input.Descendants("merchant-private-data") select nodes).FirstOrDefault();
if (privateDataNode != null && privateDataNode.HasElements && privateDataNode.Element("MERCHANT_DATA_HIDDEN") != null)
privateData = privateDataNode.Element("MERCHANT_DATA_HIDDEN").Value;
You’re missing namespace, try it like this: