我正在使用店內購買的Windows應用商店應用。進行購買時,返回一些XML。我試圖查看用戶是否成功購買了該產品。我知道我可以用LINQ來確定這一點,但我不確定如何編寫我的LINQ查詢。使用LINQ解析收據XML
private bool WasProductPurchasedFromStore(string productName)
{
string data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Receipt Version=\"1.0\" ReceiptDate=\"2012-11-24T12:22:20Z\" CertificateId=\"\" ReceiptDeviceId=\"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa\"><ProductReceipt Id=\"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb\" AppId=\"MyNamespace.MyApp_t7396xywk1mky\" ProductId=\"Upgrade\" PurchaseDate=\"2012-11-24T12:22:20Z\" ProductType=\"Durable\" /></Receipt>";
XDocument xml = XDocument.Parse(data);
// Return true if the productName is found in the XML.
// THIS IS WHERE I'M STUCK
var result = from receipt in xml
select receipt;
// Return false if the user did not make the purchase
return false;
}
如何查詢我的XML,看看是否有是有,在productName
值相匹配的ProductId
屬性值ProductReceipt
元素?
謝謝你的幫助!