我正在使用店内购买的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
元素?
谢谢你的帮助!